17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
51 public static function execute($settings, &$state)
53 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
54 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
57 if (empty($settings[
'schemaid']))
return FALSE;
59 if (empty($state[
'asset'])) {
61 if (empty($state[
'assetid'])) {
64 $state[
'asset'] = $am->getAsset($state[
'assetid']);
68 if (is_null($state[
'asset']))
return FALSE;
70 $cascade_to_children = array_get_index($settings,
'cascade_to_children', FALSE);
72 $schema = $am->getAsset($settings[
'schemaid']);
73 if (is_null($schema))
return FALSE;
74 if ($schema->type() !=
'workflow_schema')
return FALSE;
77 $assets = Array ($state[
'assetid']);
79 if (!$cascade_to_children) {
81 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getDependantChildren($state[
'assetid']);
82 foreach (array_keys($dependants) as $child_id) {
83 $assets[] = $child_id;
87 foreach ($assets as $assetid) {
88 $schema_info = $wfm->getAssetSchemaInfo($assetid, $schema->id);
89 if (!empty($schema_info)) {
90 $running_schemas = $wfm->getSchemas($assetid, NULL, TRUE);
91 if (empty($running_schemas) || !array_key_exists($schema->id, $running_schemas)) {
92 $success = $wfm->deleteSchema($assetid, $schema->id, FALSE);
93 if (!$success) $result = FALSE;
98 if ($cascade_to_children) {
99 $children = $am->getChildren($state[
'assetid']);
100 foreach (array_keys($children) as $child_id) {
101 $schema_info = $wfm->getAssetSchemaInfo($child_id, $schema->id);
102 if (!empty($schema_info)) {
103 $running_schemas = $wfm->getSchemas($child_id, NULL, TRUE);
104 if (empty($running_schemas) || !array_key_exists($schema->id, $running_schemas)) {
105 $success = $wfm->deleteSchema($child_id, $schema->id, FALSE);
106 if (!$success) $result = FALSE;
131 public static function getInterface($settings, $prefix, $write_access=FALSE)
133 $current_schemaid = array_get_index($settings,
'schemaid', 0);
134 $cascade_to_children = array_get_index($settings,
'cascade_to_children', FALSE);
138 echo translate(
'select_workflow_schema_to_remove').
' ';
139 asset_finder($prefix.
'[schemaid]', $current_schemaid, Array(
'workflow_schema' =>
'I'));
142 check_box($prefix.
'[cascade_to_children]',
'1', $cascade_to_children);
143 label(translate(
'cascade_schema_removal_to_children'), $prefix.
'[cascade_to_children]');
146 if (!empty($current_schemaid)) {
147 $schema_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($current_schemaid));
148 echo translate(
'select_workflow_schema_to_remove').
' ';
149 echo
'<b>'.$schema_info[$current_schemaid][
'name'].
' (#'.$current_schemaid.
')</b>';
151 echo translate(
'select_workflow_schema_to_remove').
' ';
152 echo
'<b>'.translate(
'trigger_schema_no_schema_specified').
'</b>';
156 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($cascade_to_children ?
'tick' :
'cross').
'.gif" alt="'.($cascade_to_children ? translate(
'yes') : translate(
'no')).
'" /> ';
157 echo translate(
'cascade_schema_removal_to_children');
160 $output = ob_get_contents();
181 $schema_info = array_get_index($request_data,
'schemaid', Array(
'assetid' => 0));
182 $settings[
'schemaid'] = array_get_index($schema_info,
'assetid', 0);
183 $settings[
'cascade_to_children'] = array_get_index($request_data,
'cascade_to_children', FALSE);