17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
39 $this->uses_trans = FALSE;
55 if (!empty($this->_running_vars[
'repositoryId'])) $repositoryId = $this->_running_vars[
'repositoryId'];
57 return parent::getCodeName().
'-'.$repositoryId;
70 return translate(
'snyc_cmis_bridge_hipo_name');
86 'name' =>
'Trash Files',
87 'function_call' => Array(
88 'process_function' =>
'processTrashFiles',
90 'running_mode' =>
'server',
93 'allow_cancel' => TRUE,
99 'name' =>
'Update Files',
100 'function_call' => Array(
101 'process_function' =>
'processUpdateFiles',
103 'running_mode' =>
'server',
105 'skip_step' => FALSE,
106 'allow_cancel' => TRUE,
112 'name' =>
'Create Files',
113 'function_call' => Array(
114 'process_function' =>
'processCreateFiles',
116 'running_mode' =>
'server',
118 'skip_step' => FALSE,
119 'allow_cancel' => TRUE,
137 if (empty($this->_running_vars[
'bridge_id'])) {
138 trigger_localised_error(
'SHAR0002', E_USER_WARNING);
143 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'bridge_id']);
144 foreach ($bridge->attr(
'wsdl') as $service_name => $url){
145 $connected = $bridge->connect($service_name, TRUE);
147 trigger_localised_error(
'SHAR0005', E_USER_WARNING, $bridge->id);
152 $repositoryId = $bridge->getRepositoryId();
153 if (empty($repositoryId)){
154 trigger_localised_error(
'SHAR0003', E_USER_WARNING, $bridge->id);
158 $this->_running_vars[
'repositoryId'] = $repositoryId;
160 $sync_info = $bridge->synchronizeCheck();
161 if (!empty($sync_info[
'delete_assetids'])) {
162 $this->_running_vars[
'todo_trash_assetids'] = $sync_info[
'delete_assetids'];
163 $this->_running_vars[
'done_trash_assetids'] = Array();
166 if (!empty($sync_info[
'update_assetids'])) {
167 $this->_running_vars[
'todo_update_assetids'] = $sync_info[
'update_assetids'];
168 $this->_running_vars[
'done_update_assetids'] = Array();
171 if (!empty($sync_info[
'create_objectIds'])){
172 $this->_running_vars[
'todo_create_objectIds'] = $sync_info[
'create_objectIds'];
173 $this->_running_vars[
'done_create_objectIds'] = Array();
176 return parent::prepare();
190 while (!empty($this->_running_vars[
'todo_trash_assetids'])) {
196 while (!empty($this->_running_vars[
'todo_update_assetids'])) {
202 while (!empty($this->_running_vars[
'todo_create_objectIds'])) {
224 if (!empty($this->_running_vars[
'todo_trash_assetids'])) {
225 $assetid = array_shift($this->_running_vars[
'todo_trash_assetids']);
226 $step_data[
'message'] =
"Trashing Asset (Id: #$assetid)";
228 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_SECURE);
229 $GLOBALS[
'SQ_SYSTEM']->am->trashAsset($assetid);
230 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
232 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
233 $asset->updateLookups();
234 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
236 $this->_running_vars[
'done_trash_assetids'][] = $assetid;
239 if (empty($this->_running_vars[
'todo_trash_assetids'])) {
240 $step_data[
'percent_done'] = 100;
241 $step_data[
'complete'] = TRUE;
243 $total = count($this->_running_vars[
'todo_trash_assetids']) + count($this->_running_vars[
'done_trash_assetids']);
244 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_trash_assetids']) / $total) * 100;
245 $step_data[
'complete'] = FALSE;
264 if (!empty($this->_running_vars[
'todo_update_assetids'])) {
265 $todo = array_shift($this->_running_vars[
'todo_update_assetids']);
267 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'bridge_id']);
268 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($todo[
'assetid']);
269 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'all')) {
270 $binary = $bridge->getObjectContents($this->_running_vars[
'repositoryId'], $todo[
'object_data'][
'cmis:objectId']);
271 if (!empty($binary)) {
273 $available_statii = $asset->getAvailableStatii();
274 if (isset($available_statii[SQ_STATUS_UNDER_CONSTRUCTION])) $asset->processStatusChange(SQ_STATUS_UNDER_CONSTRUCTION);
276 $full_path = tempnam($bridge->data_path,
"cmis:update_");
277 file_put_contents($full_path, $binary);
279 $file_name = $todo[
'object_data'][
'cmis:contentStreamFileName'];
280 $temp_info = Array(
'name' => $file_name,
'tmp_name' => $full_path,
'non_uploaded_file' => TRUE);
282 require_once SQ_INCLUDE_PATH.
'/backend_outputter.inc';
284 $edit_fns = $asset->getEditFns();
285 $edit_fns->processFileUpload($asset, $o, $prefix, $temp_info);
287 $asset->setAttrValue(
'title', $todo[
'object_data'][
'cmis:contentStreamFileName']);
288 $asset->saveAttributes();
291 foreach ($bridge->attr(
'metadata_fields') as $property => $info){
292 if ($info[
'field'] && isset($todo[
'object_data'][$property])) $metadata[$info[
'field']][0][
'value'] = $todo[
'object_data'][$property];
294 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
295 $mm->setMetadata($asset->id, $metadata);
296 $mm->regenerateMetadata($asset->id);
298 $step_data[
'message'] =
"Updated Asset $asset->name (Id: #$asset->id)";
299 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
303 $step_data[
'message'] = translate(
'hipo_skipping_asset', $asset->id);
304 $this->
_addError(translate(
'snyc_cmis_bridge_hipo_can_not_update_file_no_content_stream', $todo[
'object_data'][
'cmis:contentStreamFileName']), TRUE);
306 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id,
'all');
309 $step_data[
'message'] = translate(
'hipo_skipping_asset', $asset->id);
310 $this->
_addError(translate(
'snyc_cmis_bridge_hipo_can_not_update_file', $asset->name, $asset->id), TRUE);
313 $this->_running_vars[
'done_update_assetids'][] = $todo;
316 if (empty($this->_running_vars[
'todo_update_assetids'])) {
317 $step_data[
'percent_done'] = 100;
318 $step_data[
'complete'] = TRUE;
320 $total = count($this->_running_vars[
'todo_update_assetids']) + count($this->_running_vars[
'done_update_assetids']);
321 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_update_assetids']) / $total) * 100;
322 $step_data[
'complete'] = FALSE;
341 if (!empty($this->_running_vars[
'todo_create_objectIds'])) {
342 $todo = array_shift($this->_running_vars[
'todo_create_objectIds']);
343 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'bridge_id']);
345 $binary = $bridge->getObjectContents($this->_running_vars[
'repositoryId'], $todo[
'cmis:objectId']);
346 if (!empty($binary)) {
347 $import_link = Array(
'asset' => &$bridge,
'link_type' => SQ_LINK_TYPE_1);
349 $file_type = get_file_type($todo[
'cmis:contentStreamFileName']);
350 switch ($file_type) {
354 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'word_doc');
355 $new_asset_type =
'word_doc';
358 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'pdf_file');
359 $new_asset_type =
'pdf_file';
367 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'excel_doc');
368 $new_asset_type =
'excel_doc';
379 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'powerpoint_doc');
380 $new_asset_type =
'powerpoint_doc';
383 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'rtf_file');
384 $new_asset_type =
'rtf_file';
387 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'text_file');
388 $new_asset_type =
'text_file';
391 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'js_file');
392 $new_asset_type =
'js_file';
395 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'css_file');
396 $new_asset_type =
'css_file';
402 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'image');
403 $new_asset_type =
'image';
406 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'mp3_file');
407 $new_asset_type =
'mp3_file';
418 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'video_file');
419 $new_asset_type =
'video_file';
422 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
423 $new_asset_type =
'file';
427 $full_path = tempnam($bridge->data_path,
"cmis:create_");
428 file_put_contents($full_path, $binary);
430 $file_name = $todo[
'cmis:contentStreamFileName'];
431 $temp_info = Array(
'name' => $file_name,
'tmp_name' => $full_path,
'non_uploaded_file' => TRUE);
432 $new_file =
new $new_asset_type();
433 $new_file->_tmp[
'uploading_file'] = TRUE;
434 $new_file->setAttrValue(
'name', $file_name);
435 $new_file->setAttrValue(
'title', $todo[
'cmis:contentStreamFileName']);
436 $new_file->setAttrValue(
'allow_unrestricted', TRUE);
438 if (!$new_file->create($import_link, $temp_info)) {
439 $step_data[
'message'] = translate(
'snyc_cmis_bridge_hipo_skip_doc', $todo[
'cmis:contentStreamFileName']);
440 $this->
_addError(translate(
'snyc_cmis_bridge_hipo_can_not_create_file', $todo[
'cmis:contentStreamFileName'], $bridge->id), TRUE);
442 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($new_file->id,
'metadata');
445 foreach ($bridge->attr(
'metadata_fields') as $property => $info){
446 if ($info[
'field'] && isset($todo[$property])) $metadata[$info[
'field']][0][
'value'] = $todo[$property];
448 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
449 $mm->setMetadata($new_file->id, $metadata);
450 $mm->regenerateMetadata($new_file->id);
452 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($new_file->id,
'metadata');
454 $step_data[
'message'] =
"Created Asset $new_file->name (Id: #$new_file->id)";
455 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($new_file);
460 $step_data[
'message'] = translate(
'snyc_cmis_bridge_hipo_skip_doc', $todo[
'cmis:contentStreamFileName']);
461 $this->
_addError(translate(
'snyc_cmis_bridge_hipo_can_not_create_file_no_content_stream', $todo[
'cmis:contentStreamFileName']), TRUE);
464 $this->_running_vars[
'done_create_objectIds'][] = $todo;
468 if (empty($this->_running_vars[
'todo_create_objectIds'])) {
469 $step_data[
'percent_done'] = 100;
470 $step_data[
'complete'] = TRUE;
471 unset($this->_running_vars[
'done_create_objectIds']);
473 $total = count($this->_running_vars[
'todo_create_objectIds']) + count($this->_running_vars[
'done_create_objectIds']);
474 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_create_objectIds']) / $total) * 100;
475 $step_data[
'complete'] = FALSE;