Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
workflow_stream_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
39  {
40  Asset_Management::__construct($pm);
41 
42  $this->vars = Array(
43  'name' => Array(
44  'type' => 'text',
45  'added' => '0.1',
46  'default' => '',
47  'description' => 'Name of the workflow stream',
48  ),
49  );
50 
51  }//end constructor
52 
53 
66  function _install()
67  {
68  try {
69  if (Asset_Management::_install() === FALSE) {
70  pre_echo('FAIL?');
71  return FALSE;
72  }
73  } catch (Exception $e) {
74  pre_echo($e->getMessage());
75  return FALSE;
76  }
77 
78  $ok = TRUE;
79  $failed_schema_name = NULL;
80  $failed_schemaid = NULL;
81 
82  // Create a new "default" workflow stream underneath each
83  // Workflow Schema asset
84  if ($GLOBALS['SQ_SYSTEM']->am->installed('workflow_schema') === TRUE) {
85  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
86  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
87 
88  $schemaids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('workflow_schema');
89 
90  if (count($schemaids) > 0) {
91  pre_echo('Upgrading '.count($schemaids).' Workflow Schema asset(s) to use Workflow Stream...');
92 
93  foreach ($schemaids as $schemaid) {
94  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
95  $new_stream = new Workflow_Stream();
96  $new_stream->setAttrValue('name', 'Default Stream');
97  echo str_pad('Creating new workflow stream for schema #'.$schemaid, 60);
98  $link_info = Array(
99  'asset' => $schema,
100  'link_type' => SQ_LINK_TYPE_2,
101  'value' => 'default_stream',
102  'is_exclusive' => TRUE,
103  'is_dependant' => FALSE,
104  );
105 
106  if (!$new_stream->create($link_info)) {
107  echo '[ FAIL ]'."\n";
108  $ok = FALSE;
109  $failed_schema_name = $schema->name;
110  $failed_schemaid = $schema->id;
111  break;
112  } else {
113  echo '[ OK ] Id: #'.$new_stream->id."\n";
114  }
115 
116  // move the workflow steps underneath
117  $step_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($schemaid, SQ_LINK_TYPE_2, 'workflow_step');
118  foreach ($step_links as $step_link) {
119  echo str_pad('Re-linking step #'.$step_link['minorid'].' to stream', 60);
120  if ($GLOBALS['SQ_SYSTEM']->am->moveLink($step_link['linkid'], $new_stream->id, SQ_LINK_TYPE_2, $step_link['sort_order']) === 0) {
121  echo '[ FAIL ]'."\n";
122  $ok = FALSE;
123  $failed_schema_name = $schema->name;
124  $failed_schemaid = $schema->id;
125  break;
126  } else {
127  echo '[ OK ]'."\n";
128  }
129  }
130 
131  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($schema);
132  unset($schema);
133  }
134 
135  }//end if there are workflow schemas abounding
136 
137  if ($ok === TRUE) {
138  pre_echo('Finished upgrading '.count($schemaids).' Workflow Schema asset(s)');
139  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
140  } else {
141  pre_echo('FAILED upgrading '.count($schemaids).' Workflow Schema asset(s) - failure at schema "'.$failed_schemaid.'" (Id: #'.$failed_schemaid.')');
142  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
143  }
144  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
145  }
146 
147  return $ok;
148 
149  }//end _install()
150 
151 
158  function _getFileList()
159  {
160  return Array(
161  'css/workflow_stream_edit_fns.css',
162  'js/workflow_stream_edit_fns.js',
163  'files/wf_drag_handle.png',
164  );
165 
166  }//end _getFiles()
167 
168 
169 }//end class
170 
171 ?>