17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
52 public static function execute($settings, &$state)
54 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
55 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
56 $master_list = Array();
59 if (empty($settings[
'schemaid']) && (!isset($settings[
'removeall']) && !$settings[
'removeall'])) {
63 if (empty($state[
'asset'])) {
65 if (empty($state[
'assetid'])) {
68 $state[
'asset'] = $am->getAsset($state[
'assetid']);
72 if (is_null($state[
'asset']))
return FALSE;
74 $remove_all = array_get_index($settings,
'removeall', FALSE);
75 $cascade = array_get_index($settings,
'cascade', FALSE);
79 $master_list = $mm->getSchemas($state[
'asset']->
id);
82 $schema = $am->getAsset($settings[
'schemaid']);
88 if ((is_null($schema) || $schema->type() !=
'metadata_schema') && !$remove_all) {
90 }
else if (empty($master_list) && $remove_all && (is_null($schema) || $schema->type() !=
'metadata_schema')) {
96 foreach ($master_list as $schema_to_delete => $grant_return) {
97 $result[] = $mm->deleteSchema($state[
'asset']->
id, $schema_to_delete);
100 $result = $mm->deleteSchema($state[
'asset']->
id, $schema->id);
105 foreach ($master_list as $schema_to_delete => $grant_return) {
106 $schema_vars[] = Array(
107 'assetids' => Array($state[
'asset']->
id),
109 'schemaid' => $schema_to_delete,
110 'previous_access' => NULL,
116 $state[
'asset']->
id => Array(
117 'type_code' => $state[
'asset']->
type(),
120 'schema_changes' => $schema_vars,
123 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
124 $errors = $hh->freestyleHIPO(
'hipo_job_edit_metadata_schemas', $vars);
125 $result = empty($errors);
127 $schema_vars[] = Array(
128 'assetids' => Array($state[
'asset']->
id),
130 'schemaid' => $settings[
'schemaid'],
131 'previous_access' => NULL,
136 $state[
'asset']->
id => Array(
137 'type_code' => $state[
'asset']->
type(),
140 'schema_changes' => $schema_vars,
143 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
144 $errors = $hh->freestyleHIPO(
'hipo_job_edit_metadata_schemas', $vars);
145 $result = empty($errors);
150 if (is_array($result)) {
151 $trigger_result = TRUE;
152 foreach ($result as $result_value) {
153 if (!$result_value) $trigger_result = FALSE;
157 $result = $trigger_result;
164 'assetid' => $state[
'asset']->
id,
165 'schemaid' => $settings[
'schemaid'],
166 'remove_all' => $remove_all,
167 'cascade' => $cascade,
184 public static function getInterface($settings, $prefix, $write_access=FALSE)
186 $current_schemaid = array_get_index($settings,
'schemaid', 0);
187 $remove_all = array_get_index($settings,
'removeall', 0);
188 $cascade = array_get_index($settings,
'cascade', 0);
192 echo translate(
'trigger_schema_remove_schema_message');
193 asset_finder($prefix.
'[schemaid]', $current_schemaid, Array(
'metadata_schema' =>
'I'));
195 check_box($prefix.
'[removeall]',
'1', $remove_all,
'if (this.checked == true) { if (!confirm("'.translate(
'trigger_schema_remove_all_schema_confirm_message').
'")) { this.checked = false; } }');
196 label(translate(
'trigger_schema_remove_all_schema_message'));
198 check_box($prefix.
'[cascade]',
'1', $cascade);
199 label(translate(
'cascade_schema_changes'), $prefix.
'[cascade]');
202 if (!empty($current_schemaid)) {
203 $schema_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($current_schemaid));
204 echo translate(
'trigger_schema_remove_schema_message').
' ';
205 echo
'<b>'.$schema_info[$current_schemaid][
'name'].
' (#'.$current_schemaid.
')</b>';
207 echo translate(
'trigger_schema_remove_schema_message').
' ';
208 echo
'<b>'.translate(
'trigger_schema_no_schema_message').
'</b>';
211 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($remove_all ?
'tick' :
'cross').
'.gif" alt="'.($remove_all ? translate(
'yes') : translate(
'no')).
'" /> ';
212 echo translate(
'trigger_schema_remove_all_schema_message');
214 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade ?
'tick' :
'cross').
'.gif" alt="'.($cascade ? translate(
'yes') : translate(
'no')).
'" /> ';
215 echo translate(
'cascade_schema_changes');
218 $output = ob_get_contents();
239 $schema_info = array_get_index($request_data,
'schemaid', Array(
'assetid' => 0));
240 $settings[
'schemaid'] = array_get_index($schema_info,
'assetid', 0);
241 $settings[
'removeall'] = array_get_index($request_data,
'removeall', FALSE);
242 $settings[
'cascade'] = array_get_index($request_data,
'cascade', FALSE);
257 public static function getLocks($settings, &$state)
259 return Array($state[
'assetid'] => Array(
'metadata'));