FIX: Added option to force migration of partial filters[t24074]
git-svn-id: http://svn.resourcespace.com/svn/rs/trunk@16529 c08608d7-6e46-0410-86ca-f2a6f1370df5
This commit is contained in:
parent
9556a4bd05
commit
1acbbe7234
|
@ -152,7 +152,7 @@ function populate_resource_nodes($startingref=0)
|
|||
return true;
|
||||
}
|
||||
|
||||
function migrate_filter($filtertext)
|
||||
function migrate_filter($filtertext,$allowpartialmigration=false)
|
||||
{
|
||||
if(trim($filtertext) == "")
|
||||
{
|
||||
|
@ -233,12 +233,12 @@ function migrate_filter($filtertext)
|
|||
$nodeidx = array_search(mb_strtolower($rulevalue), array_map("mb_strtolower", array_column($all_valid_nodes, 'name')));
|
||||
|
||||
if($nodeidx !== false)
|
||||
{
|
||||
{
|
||||
$nodeid = $all_valid_nodes[$nodeidx]["ref"];
|
||||
$logtext .= "FILTER MIGRATION: --- field option (node) exists, node id #: " . $all_valid_nodes[$nodeidx]["ref"] . "\n";
|
||||
|
||||
$nodeinsert[] = "('" . $new_filter_rule . "','" . $nodeid . "','" . $node_condition . "')";
|
||||
$rulevalid = true; // Atleast one rule is valid so the filter can be created
|
||||
if($allowpartialmigration){$rulevalid = true;} // Atleast one rule is valid so the filter can be created
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2,10 +2,47 @@
|
|||
include_once __DIR__ . "/../../include/db.php";
|
||||
include_once __DIR__ . "/../../include/migration_functions.php";
|
||||
|
||||
if($search_filter_nodes && (!isset($sysvars["SEARCH_FILTER_MIGRATION"]) || $sysvars["SEARCH_FILTER_MIGRATION"] == 0))
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// To migrate filters which contain invalid values run with the option --force
|
||||
// i.e. command line access: php 005_migrate_search_filters.php --force
|
||||
// web access : migrate/scripts/005_search_filters.php?force=true
|
||||
//
|
||||
// This option will create the filter if at least one condition can find a node value.
|
||||
// If no values are found the filter migration will still fail.
|
||||
// Only filters that have failed migration will be processed in this case.
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
if(PHP_SAPI != 'cli')
|
||||
{
|
||||
$allowpartialmigration = getval('force',false);
|
||||
if($allowpartialmigration)
|
||||
{
|
||||
// Only allow admin users to do force filter creation because the filters should be checked manually first
|
||||
include_once __DIR__ . "/../../include/authenticate.php";
|
||||
if(!checkperm('v')){exit("permission denied.");}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$cli_long_options = array('force');
|
||||
$allowpartialmigration = false;
|
||||
foreach(getopt('', $cli_long_options) as $option_name => $option_value)
|
||||
{
|
||||
if($option_name == 'force')
|
||||
{
|
||||
$allowpartialmigration = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($search_filter_nodes && (!isset($sysvars["SEARCH_FILTER_MIGRATION"]) || $sysvars["SEARCH_FILTER_MIGRATION"] == 0 || $allowpartialmigration))
|
||||
{
|
||||
$notification_users = get_notification_users();
|
||||
$groups = sql_query("SELECT ref, name,search_filter FROM usergroup WHERE search_filter_id IS NULL OR search_filter_id=0");
|
||||
$groups_sql = "SELECT ref, name,search_filter FROM usergroup WHERE ";
|
||||
if($allowpartialmigration){$groups_sql.='search_filter_id=-1';}
|
||||
else {$groups_sql .= "search_filter_id IS NULL OR search_filter_id=0";}
|
||||
$groups = sql_query($groups_sql);
|
||||
foreach($groups as $group)
|
||||
{
|
||||
$filtertext = trim($group["search_filter"]);
|
||||
|
@ -15,7 +52,7 @@ if($search_filter_nodes && (!isset($sysvars["SEARCH_FILTER_MIGRATION"]) || $sysv
|
|||
}
|
||||
|
||||
// Migrate unless marked not to due to failure (flag will be reset if group is edited)
|
||||
$migrateresult = migrate_filter($filtertext);
|
||||
$migrateresult = migrate_filter($filtertext,$allowpartialmigration);
|
||||
if(is_numeric($migrateresult))
|
||||
{
|
||||
message_add(array_column($notification_users,"ref"), $lang["filter_migrate_success"] . ": '" . $filtertext . "'",generateURL($baseurl_short . "pages/admin/admin_group_management_edit.php",array("ref"=>$group["ref"])));
|
||||
|
|
Loading…
Reference in New Issue