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

Removed unused system settings for "System and Server" section #14877

Merged
merged 4 commits into from
Dec 9, 2019
Merged

Removed unused system settings for "System and Server" section #14877

merged 4 commits into from
Dec 9, 2019

Conversation

Ruslan-Aleev
Copy link
Collaborator

@Ruslan-Aleev Ruslan-Aleev commented Dec 7, 2019

What does it do?

Removed unused system settings for "System and Server" section.

These settings are found only in the "System Settings", do not participate in the remaining code:

  • resolve_hostnames
  • server_protocol (Honor value of "server_protocol" #13269)
    The server_protocol setting is confusing, I saw posts, for example, when setting up redirects, people are looking for the cause of the problem, including in this setting, not knowing that it does not work at all :)

These settings are not used in 3.x; they were specified in Evolution:

In the future, I will check the settings in other sections.

Related issue(s)/PR(s)

#14539 (comment)

Comment on lines 87 to 89
$_lang['setting_access_policies_version'] = 'Access Policy Schema Version';
$_lang['setting_access_policies_version_desc'] = 'The version of the Access Policy system. DO NOT CHANGE.';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these should stay because the related system setting seems to be used during the setup/upgrade of MODX:

/* Access Policy changes (have to happen post package install) */
/* setup a setting to run this only once */
$setting = $modx->getObject(modSystemSetting::class,array(
'key' => 'access_policies_version',
'value' => '1.0',
));
if (!$setting) {
/* truncate permissions in modAccessPermission and migrate to modAccessPolicyTemplate objects from modAccessPolicy.data
* first get the standard policies, and then array_diff with Admin policy and unknown policies
* if an unknown policy doesnt contain any new permissions that arent in Admin policy,
* just switch it to the Admin Policy Template. Otherwise, create a new AP template
* based on the Policy's name (first look for an existing one).
*/
/* get admin policy and list of standard policies */
$standards = array('Administrator','Resource','Load Only','Load, List and View','Object','Element');
$adminPolicy = $modx->getObject(modAccessPolicy::class, array('name' => 'Administrator'));
$adminPolicyData = $adminPolicy ? $adminPolicy->get('data') : array();
$adminPolicyTpl = $modx->getObject(modAccessPolicyTemplate::class, array('name' => 'AdministratorTemplate'));
if (!$adminPolicyTpl) {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find Administrator Access Policy Template');
}
$adminPolicyTplGroup = $adminPolicyTpl ? $adminPolicyTpl->get('template_group') : 1;
/* get all existing policies */
$c = $modx->newQuery(modAccessPolicy::class);
$c->sortby('name','ASC');
$policies = $modx->getCollection(modAccessPolicy::class, $c);
/** @var modAccessPolicy $policy */
foreach ($policies as $policy) {
/* standard policies */
if (in_array($policy->get('name'),$standards)) {
if ($policy->get('template') != 0) continue;
$id = $adminPolicyTpl ? $adminPolicyTpl->get('id') : 3; /* default to object */
switch ($policy->get('name')) {
case 'Resource':
$policyTpl = $modx->getObject(modAccessPolicyTemplate::class, array('name' => 'ResourceTemplate'));
if ($policyTpl) {
$id = $policyTpl->get('id');
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find Resource Access Policy Template');
}
break;
case 'Element':
$policyTpl = $modx->getObject(modAccessPolicyTemplate::class, array('name' => 'ElementTemplate'));
if ($policyTpl) {
$id = $policyTpl->get('id');
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find Element Access Policy Template');
}
break;
case 'Object':
case 'Load, List and View':
case 'Load Only':
$policyTpl = $modx->getObject(modAccessPolicyTemplate::class, array('name' => 'ObjectTemplate'));
if ($policyTpl) {
$id = $policyTpl->get('id');
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR,'Could not find Object Access Policy Template');
}
break;
case 'Administrator':
default:
break;
}
$modx->log(xPDO::LOG_LEVEL_DEBUG,'Setting template to '.$id.' for standard '.$policy->get('name'));
/* prevent duplicate standard policies */
$policyExists = $modx->getObject(modAccessPolicy::class, array(
'template' => $id,
'name' => $policy->get('name'),
));
if ($policyExists) {
$policy->remove();
} else {
$policy->set('template',$id);
$policy->save();
}
unset($policyTpl,$policy,$id,$policyExists);
} else {
$modx->log(xPDO::LOG_LEVEL_DEBUG,'Found non-standard policy: '.$policy->get('name'));
/* non-standard policies */
if (!$policyTpl = $policy->getOne('Template')) {
$policyTpl = $modx->getObject(modAccessPolicyTemplate::class, array(
'name' => $policy->get('name'),
));
}
if (!$policyTpl) {
/* array_diff data with standard admin policy */
$data = $policy->get('data');
$diff = array_diff_key($data,$adminPolicyData);
$modx->log(xPDO::LOG_LEVEL_DEBUG,'Diff: '.print_r($diff,true));
/* if the unknown policy has all the perms and no new perms of the admin
* policy, just set its tpl to the admin policy tpl
*/
if (empty($diff) && $adminPolicyTpl) {
$policy->set('template',$adminPolicyTpl->get('id'));
$policy->save();
/* otherwise create a custom policy tpl */
} else {
$policyTpl = $modx->newObject(modAccessPolicyTemplate::class);
$policyTpl->fromArray(array(
'name' => $policy->get('name').'Template',
'template_group' => $adminPolicyTplGroup,
'description' => $policy->get('description'),
));
$lexicon = $policy->get('lexicon');
if (!empty($lexicon)) {
$modx->log(xPDO::LOG_LEVEL_DEBUG,'Setting lexicon to '.$lexicon.' for policy '.$policy->get('name'));
$policyTpl->set('lexicon',$lexicon);
}
$policyTpl->save();
$modx->log(xPDO::LOG_LEVEL_DEBUG,'Setting template to '.$policyTpl->get('id').' for '.$policy->get('name'));
$policy->set('template',$policyTpl->get('id'));
$policy->save();
$permissions = $modx->getCollection(modAccessPermission::class, array(
'policy' => $policy->get('id'),
));
// add permissions to tpl
foreach ($permissions as $permission) {
// prevent duplicate permissions
/** @var modAccessPermission $permission */
$permExists = $modx->getObject(modAccessPermission::class, array(
'name' => $permission->get('name'),
'template' => $policyTpl->get('id'),
));
if ($permExists) {
$permission->remove();
} else {
$permission->set('template',$policyTpl->get('id'));
$permission->save();
}
}
}
}
}
}
unset($policy,$permission,$permissions,$policies,$policy,$policyTpl,$adminPolicy,$adminPolicyData,$adminPolicyTpl,$adminPolicyTplGroup,$data);
/* now remove all 0 template permissions */
$permissions =$modx->getCollection(modAccessPermission::class, array('template' => 0));
foreach ($permissions as $permission) { $permission->remove(); }
unset($permissions,$permission);
/* drop policy index from modAccessPermission */
$class = modAccessPermission::class;
$table = $modx->getTableName($class);
$sql = "ALTER TABLE {$table} DROP INDEX policy";
$modx->exec($sql);
/* drop policy field from modAccessPermission */
$sql = "ALTER TABLE {$table} DROP COLUMN policy";
$modx->exec($sql);
/* add setting so that this runs only once to prevent errors or goof-ups */
$setting = $modx->newObject(modSystemSetting::class);
$setting->set('key','access_policies_version');
$setting->set('namespace','core');
$setting->set('area','system');
$setting->set('value','1.0');
$setting->save();
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I deleted only the lexicon, the setting itself is not present in the system settings grid. https://github.com/modxcms/revolution/blob/3.x/_build/data/transport.core.system_settings.php

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like it might be a remnant from the upgrade to v2.0.5. I believe we're not planning to support 3.0 upgrades from anything but 2.6/2.7, so that looks like code which could also be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong. This setting is specified during the upgrade. Now I will return the lexicon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mark-H Sent a commit before your comment :)
I think that all lexicons can be cleaned with a separate PR group. Let this lexicon remain for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready-for-merging Pull request reviewed and tested and ready for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants