Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
workflow_schema.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/folder/folder.inc';
18 
30 class Workflow_Schema extends Folder
31 {
32 
33 
40  function __construct($assetid=0)
41  {
42  parent::__construct($assetid);
43 
44  }//end constructor
45 
46 
47 
68  protected function _createAdditional(Array &$link)
69  {
70  $ok = TRUE;
71 
72  $GLOBALS['SQ_SYSTEM']->am->includeAsset('workflow_stream');
73  $new_stream = new Workflow_Stream();
74  $new_stream->setAttrValue('name', 'Default Stream');
75 
76  $link_info = Array(
77  'asset' => $this,
78  'link_type' => SQ_LINK_TYPE_2,
79  'value' => 'default_stream',
80  'is_exclusive' => TRUE,
81  'is_dependant' => FALSE,
82  );
83 
84  if (!$new_stream->create($link_info)) {
85  $ok = FALSE;
86  break;
87  }
88 
89  return $ok;
90 
91  }//end _createAdditional()
92 
93 
100  public function lockTypes()
101  {
102  $lock_types = parent::lockTypes();
103  $lock_types['content'] = ($lock_types['attributes'] | $lock_types['links']);
104  return $lock_types;
105 
106  }//end lockTypes()
107 
108 
116  public function _getAllowedLinks()
117  {
118  return Array(
119  SQ_LINK_TYPE_1 => Array(),
120  SQ_LINK_TYPE_2 => Array(
121  'workflow_stream' => Array(
122  'card' => 'M',
123  'exclusive' => FALSE,
124  ),
125  'workflow_step' => Array(
126  'card' => 'M',
127  'exclusive' => FALSE,
128  ),
129  ),
130  SQ_LINK_TYPE_3 => Array(),
131  SQ_LINK_NOTICE => Array(),
132  );
133 
134  }//end _getAllowedLinks()
135 
136 
157  public function prepareLink(Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
158  {
159  // if this is a workflow step then we need to make it a dependant link
160  if ($side_of_link == 'major' && ($asset instanceof Workflow_Stream) && $dependant != '1') {
161  $dependant = '1';
162  return TRUE;
163  }
164 
165  return FALSE;
166 
167  }//end prepareLink()
168 
169 
178  public function saveWebPaths(Array $paths)
179  {
180  return TRUE;
181 
182  }//end saveWebPaths()
183 
184 
197  public function delete($release_lock=TRUE, $check_locked=TRUE)
198  {
199  // lets have with us all the assets the schema we are deleteing is applied to
200  $wfm = $GLOBALS['SQ_SYSTEM']->getWorkflowManager();
201  $schema_treeids_sql = 'SELECT
202  assetid, granted, wflow
203  FROM (sq_ast_lnk_tree ta
204  JOIN sq_ast_lnk la ON ta.linkid = la.linkid
205  JOIN sq_ast_wflow wa ON la.minorid = wa.assetid)
206  WHERE wa.schemaid = :schemaid
207  AND NOT EXISTS (
208  SELECT * FROM (sq_ast_lnk_tree tb
209  JOIN sq_ast_lnk lb ON tb.linkid = lb.linkid
210  JOIN sq_ast_wflow wb ON lb.minorid = wb.assetid)
211  WHERE wb.schemaid = wa.schemaid
212  AND length(ta.treeid) - LENGTH(tb.treeid) = :tree_size
213  AND SUBSTR(ta.treeid, 1, LENGTH(ta.treeid) - :tree_size_1) = tb.treeid
214  AND wa.granted = wb.granted
215  AND wa.cascades = wb.cascades
216  ) ORDER BY assetid';
217 
218  $query = MatrixDAL::preparePdoQuery($schema_treeids_sql);
219  MatrixDAL::bindValueToPdo($query, 'schemaid', $this->id);
220  MatrixDAL::bindValueToPdo($query, 'tree_size', SQ_CONF_ASSET_TREE_SIZE);
221  MatrixDAL::bindValueToPdo($query, 'tree_size_1', SQ_CONF_ASSET_TREE_SIZE);
222  $results = MatrixDAL::executePdoAssoc($query);
223 
224  // check for running schema
225  $running_schema = FALSE;
226  $running_id = array();
227  foreach ($results as $index => $info) {
228  if(!empty($info['wflow'])) {
229  $running_schema = TRUE;
230  $running_id[] = $info['assetid'];
231  }
232  }
233  if($running_schema) {
234  trigger_error('Purged Workflow Schema Id #'.$this->id.' is applied and running on assets with Id: '. implode(', ', $running_id), E_USER_NOTICE);
235  return FALSE;
236  }
237 
238  // guess what? someone is deleting schema even when it might be applied to assets.
239  // lets be smart and remove from the assets where schema is NOT running
240  foreach ($results as $index => $info) {
241  if(empty($info['wflow'])) {
242  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
243  $wfm->deleteSchema($info['assetid'], $this->id);
244  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
245  } else {
246  // oops someone is deleting the workflow without considering that it might
247  // be running on some assets.
248  trigger_error('Purged Workflow Schema Id #'.$this->id.' is applied and running on Asset Id #'.$info['assetid'].'.', E_USER_NOTICE);
249  return FALSE;
250  }
251  }
252 
253  // we have now removed the db entries removed...all set to delete the schema
254  if(!parent::delete($release_lock, $check_locked)) {
255  return FALSE;
256  }
257 
258  return TRUE;
259 
260  }//end delete()
261 
262 
263 }//end class
264 
265 ?>