Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_remove_workflow_schema.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
18 
30 {
31 
32 
51  public static function execute($settings, &$state)
52  {
53  $am =& $GLOBALS['SQ_SYSTEM']->am;
54  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
55 
56  // check required settings
57  if (empty($settings['schemaid'])) return FALSE;
58 
59  if (empty($state['asset'])) {
60  // grab the asset if assetid is given, but not the asset.
61  if (empty($state['assetid'])) {
62  return FALSE;
63  } else {
64  $state['asset'] = $am->getAsset($state['assetid']);
65  }
66  }
67 
68  if (is_null($state['asset'])) return FALSE;
69 
70  $cascade_to_children = array_get_index($settings, 'cascade_to_children', FALSE);
71 
72  $schema = $am->getAsset($settings['schemaid']);
73  if (is_null($schema)) return FALSE;
74  if ($schema->type() != 'workflow_schema') return FALSE;
75 
76  $result = TRUE;
77  $assets = Array ($state['assetid']);
78 
79  if (!$cascade_to_children) {
80  //This part ensures schemas are removed from depedant children of a single targeted asset (cascade off).
81  $dependants = $GLOBALS['SQ_SYSTEM']->am->getDependantChildren($state['assetid']);
82  foreach (array_keys($dependants) as $child_id) {
83  $assets[] = $child_id;
84  }
85  }
86 
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;
94  }
95  }
96  }
97 
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;
107  }
108  }
109  }
110  }
111 
112  if (!$result) {
113  return FALSE;
114  } else {
115  return TRUE;
116  }
117 
118  }//end execute()
119 
120 
131  public static function getInterface($settings, $prefix, $write_access=FALSE)
132  {
133  $current_schemaid = array_get_index($settings, 'schemaid', 0);
134  $cascade_to_children = array_get_index($settings, 'cascade_to_children', FALSE);
135 
136  ob_start();
137  if ($write_access) {
138  echo translate('select_workflow_schema_to_remove').' ';
139  asset_finder($prefix.'[schemaid]', $current_schemaid, Array('workflow_schema' => 'I'));
140 
141  echo '<br />';
142  check_box($prefix.'[cascade_to_children]', '1', $cascade_to_children);
143  label(translate('cascade_schema_removal_to_children'), $prefix.'[cascade_to_children]');
144 
145  } else {
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>';
150  } else {
151  echo translate('select_workflow_schema_to_remove').' ';
152  echo '<b>'.translate('trigger_schema_no_schema_specified').'</b>';
153  }
154 
155  echo '<br />';
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');
158  }
159 
160  $output = ob_get_contents();
161  ob_end_clean();
162 
163  return $output;
164 
165  }//end getInterface()
166 
167 
179  public static function processInterface(&$settings, $request_data)
180  {
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);
184 
185  return FALSE;
186 
187  }//end processInterface()
188 
189 
190 }//end class
191 
192 ?>