Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make authority a unique index on modUserGroupRole #16587

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/model/schema/modx.mysql.schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1284,12 +1284,12 @@
<object class="modUserGroupRole" table="user_group_roles" extends="xPDO\Om\xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="191" phptype="string" null="false" index="unique" />
<field key="description" dbtype="mediumtext" phptype="string" />
<field key="authority" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="9999" index="index" />
<field key="authority" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="9999" index="unique" />

<index alias="name" name="name" primary="false" unique="true" type="BTREE">
<column key="name" length="" collation="A" null="false" />
</index>
<index alias="authority" name="authority" primary="false" unique="false" type="BTREE">
<index alias="authority" name="authority" primary="false" unique="true" type="BTREE">
<column key="authority" length="" collation="A" null="false" />
</index>

Expand Down
4 changes: 2 additions & 2 deletions core/src/Revolution/mysql/modUserGroupRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class modUserGroupRole extends \MODX\Revolution\modUserGroupRole
'phptype' => 'integer',
'null' => false,
'default' => 9999,
'index' => 'index',
'index' => 'unique',
),
),
'indexes' =>
Expand All @@ -69,7 +69,7 @@ class modUserGroupRole extends \MODX\Revolution\modUserGroupRole
array (
'alias' => 'authority',
'primary' => false,
'unique' => false,
'unique' => true,
'type' => 'BTREE',
'columns' =>
array (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/* convert the authority index to be unique on modUserGroupRole */

/**
* @var modX $modx
* @var modInstallVersion $this
*/

$class = \MODX\Revolution\modUserGroupRole::class;
$table = $modx->getTableName(\MODX\Revolution\modUserGroupRole::class);

$description = $this->install->lexicon('drop_index', ['index' => 'authority', 'table' => $table]);
$this->processResults($class, $description, [$modx->manager, 'removeIndex'], [$class, 'authority']);
$description = $this->install->lexicon('add_index', ['index' => 'authority', 'table' => $table]);
if (!$this->processResults($class, $description, [$modx->manager, 'addIndex'], [$class, 'authority']))

Check failure on line 16 in setup/includes/upgrades/common/3.1.0-modify-usergrouprole-authority-index.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space after closing parenthesis; found newline
{
$this->runner->addResult(modInstallRunner::RESULT_FAILURE, $this->install->lexicon('authority_unique_index_error'));
}
1 change: 1 addition & 0 deletions setup/includes/upgrades/mysql/3.1.0-pl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

/* run upgrades common to all db platforms */
include dirname(__DIR__) . '/common/3.1.0-remove-deprecated-resource-fields.php';
include dirname(__DIR__) . '/common/3.1.0-modify-usergrouprole-authority-index.php';
1 change: 1 addition & 0 deletions setup/lang/en/upgrades.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$_lang['alter_usermessage_messageread'] = 'Changed modUserMessage `messageread` field to `read`.';
$_lang['alter_usermessage_postdate'] = 'Changed modUserMessage `postdate` field from an INT to a DATETIME and to name `date_sent`.';
$_lang['alter_usermessage_subject'] = 'Changed modUserMessage `subject` field from VARCHAR(60) to VARCHAR(255).';
$_lang['authority_unique_index_error'] = 'Multiple modUserGroup records with the same authority were found. You will need to update these to have unique authority values and then re-run the upgrade.';
$_lang['change_column'] = 'Changed `[[+old]]` field to `[[+new]]` on table [[+table]].';
$_lang['change_default_value'] = 'Changed default value for column `[[+column]]` to "[[+value]]" on table [[+table]].';
$_lang['connector_acls_removed'] = 'Removed connector context ACLs.';
Expand Down
Loading