/pages/tools/run_autocomplete_macros.php?col=4&field=25&force=true ^ The collections of resources to be processed. ^ The resource type field who's autocomplete macro will be run. ^ Overwrite existing values. HELP; $cli_options = array(); if (PHP_SAPI == 'cli') { $cli_options = getopt('', array('help','field:','col:','force')); } if (array_key_exists('help', $cli_options)) { exit($help_text . PHP_EOL); } $force_update = false; if (array_key_exists('force', $cli_options)) { $force_update = true; } $force_update = (bool) getval("force", $force_update); $collection = 0; if (array_key_exists('col', $cli_options)) { $collection = $cli_options['col']; } $collection = getval("col", $collection); if (!is_numeric($collection)) { exit('Collection reference provided must be numeric.' . PHP_EOL); } $collection = (int) $collection; $field = 0; if (array_key_exists('field', $cli_options)) { $field = $cli_options['field']; } $field = getval("field", $field); if (!is_numeric($field)) { exit('Metadata field reference provided must be numeric.' . PHP_EOL); } $field = (int) $field; if ($field !== 0) { $valid_fields = get_resource_type_fields("", "ref", "asc", "", array(), true); $valid_fields = array_column($valid_fields, 'ref'); if (!in_array($field, $valid_fields)) { exit('Invalid resource type field reference supplied.' . PHP_EOL); } } if ($collection === 0) { $resources = ps_array("SELECT ref value FROM resource WHERE ref > 0"); } else { $resources = get_collection_resources($collection); if (is_array($resources) && count($resources) == 0) { exit('Invalid or empty collection reference supplied. Nothing to do.' . PHP_EOL); } } foreach ($resources as $resource) { $fields_updated = autocomplete_blank_fields((int) $resource, $force_update, true, $field); foreach ($fields_updated as $key => $val) { echo "Resource " . $resource . ", Field " . $key . " = " . $val . (PHP_SAPI == 'cli' ? PHP_EOL : '
'); } }