17 require_once SQ_INCLUDE_PATH.
'/asset_management.inc';
40 Asset_Management::__construct($pm);
46 'type' =>
'serialise',
49 'types_restriction' => Array(
51 'type' =>
'serialise',
58 'description' =>
'The full name of the page',
62 'short_name' => Array(
66 'description' =>
'The short name of the page',
74 'description' =>
'The root node to restrict to. DEPRECIATED in v0.2 and up',
82 'description' =>
'The API Key',
86 'create_attributes' => Array(
90 'parameters' => Array(
91 'allow_empty' => FALSE,
94 'allow_json' => Array(
98 'parameters' => Array(
99 'allow_empty' => FALSE,
102 'ignore_permissions' => Array(
106 'parameters' => Array(
107 'allow_empty' => FALSE,
110 'get_general' => Array(
114 'parameters' => Array(
115 'allow_empty' => FALSE,
118 'get_attributes' => Array(
122 'parameters' => Array(
123 'allow_empty' => FALSE,
126 'set_attribute' => Array(
130 'parameters' => Array(
131 'allow_empty' => FALSE,
134 'get_metadata' => Array(
138 'parameters' => Array(
139 'allow_empty' => FALSE,
142 'set_metadata' => Array(
146 'parameters' => Array(
147 'allow_empty' => FALSE,
150 'trash_asset' => Array(
154 'parameters' => Array(
155 'allow_empty' => FALSE,
158 'get_parents' => Array(
162 'parameters' => Array(
163 'allow_empty' => FALSE,
166 'get_children' => Array(
170 'parameters' => Array(
171 'allow_empty' => FALSE,
174 'get_permissions' => Array(
178 'parameters' => Array(
179 'allow_empty' => FALSE,
182 'create_asset' => Array(
186 'parameters' => Array(
187 'allow_empty' => FALSE,
190 'get_asset_types' => Array(
194 'parameters' => Array(
195 'allow_empty' => FALSE,
198 'get_locks_info' => Array(
202 'parameters' => Array(
203 'allow_empty' => FALSE,
206 'acquire_lock' => Array(
210 'parameters' => Array(
211 'allow_empty' => FALSE,
214 'release_lock' => Array(
218 'parameters' => Array(
219 'allow_empty' => FALSE,
222 'create_link' => Array(
226 'parameters' => Array(
227 'allow_empty' => FALSE,
230 'remove_link' => Array(
234 'parameters' => Array(
235 'allow_empty' => FALSE,
238 'move_link' => Array(
242 'parameters' => Array(
243 'allow_empty' => FALSE,
246 'update_link' => Array(
250 'parameters' => Array(
251 'allow_empty' => FALSE,
254 'get_link_id' => Array(
258 'parameters' => Array(
259 'allow_empty' => FALSE,
262 'get_asset_tree' => Array(
266 'parameters' => Array(
267 'allow_empty' => FALSE,
270 'get_keywords_replacements' => Array(
274 'parameters' => Array(
275 'allow_empty' => FALSE,
278 'set_asset_status' => Array(
282 'parameters' => Array(
283 'allow_empty' => FALSE,
286 'get_web_path' => Array(
290 'parameters' => Array(
291 'allow_empty' => FALSE,
294 'set_web_path' => Array(
298 'parameters' => Array(
299 'allow_empty' => FALSE,
302 'force_simple_edit' => Array(
306 'parameters' => Array(
307 'allow_empty' => FALSE,
310 'get_workflow_schema' => Array(
314 'parameters' => Array(
315 'allow_empty' => FALSE,
318 'set_file_content' => Array(
322 'parameters' => Array(
323 'allow_empty' => FALSE,
326 'import_assets' => Array(
330 'parameters' => Array(
331 'allow_empty' => FALSE,
334 'get_roles' => Array(
338 'parameters' => Array(
339 'allow_empty' => FALSE,
342 'execute_html_tidy' => Array(
346 'parameters' => Array(
347 'allow_empty'=> FALSE,
350 'use_enhanced_js' => Array(
354 'parameters' => Array(
355 'allow_empty'=> FALSE,
358 'get_lineage' => Array(
362 'parameters' => Array(
363 'allow_empty'=> FALSE,
366 'get_lineage_from_url' => Array(
370 'parameters' => Array(
371 'allow_empty'=> FALSE,
374 'get_url_from_lineage' => Array(
378 'parameters' => Array(
379 'allow_empty'=> FALSE,
383 'batch_requests' => Array(
387 'parameters' => Array(
388 'allow_empty'=> FALSE,
391 'clone_asset' => Array(
395 'parameters' => Array(
396 'allow_empty'=> FALSE,
399 'show_diff' => Array(
403 'parameters' => Array(
404 'allow_empty'=> FALSE,
407 'get_context' => Array(
411 'parameters' => Array(
412 'allow_empty'=> FALSE,
415 'set_context' => Array(
419 'parameters' => Array(
420 'allow_empty'=> FALSE,
423 'get_metadata_schema' => Array(
427 'parameters' => Array(
428 'allow_empty'=> FALSE,
431 'sync_context' => Array(
435 'parameters' => Array(
436 'allow_empty'=> FALSE,
454 if (!parent::_upgrade($current_version))
return FALSE;
456 $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(),
'name'));
458 if (version_compare($current_version,
'0.2',
'<')) {
461 pre_echo(
'STARTING '.$asset_name.
' UPGRADE - FROM VERSION 0.1');
462 $apis = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'js_api', FALSE, TRUE);
464 foreach ($apis as $assetid => $type_code) {
465 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'js_api');
466 if (is_null($asset))
continue;
469 $root_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE,
'', FALSE,
'major',
'root');
470 $current_root_node_id = $asset->attr(
'root_node');
473 if (!empty($current_root_node_id)) {
475 foreach ($root_links as $root_link) {
476 if ($root_link[
'minorid'] == $current_root_node_id) {
482 $current_root_node = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_root_node_id);
483 if (!is_null($current_root_node)) {
484 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'links');
485 $new_link = $GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($asset, $current_root_node, SQ_LINK_NOTICE,
'root');
486 if (!empty($new_link)) $count++;
487 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id,
'links');
492 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
496 pre_echo(
'Updated - '.$count.
' Javascript Api(s)...');
497 pre_echo($asset_name.
' UPGRADE COMPLETE - FROM VERSION 0.1');
501 if (version_compare($current_version,
'0.3',
'<')) {
504 pre_echo(
'STARTING '.$asset_name.
' UPGRADE - TO VERSION 0.3 - FIXING Default API Key');
505 $apis = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'js_api', FALSE, TRUE);
507 foreach ($apis as $assetid => $type_code) {
508 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'js_api');
509 if (is_null($asset))
continue;
510 $key = $asset->attr(
'api_key');
513 $new_key = rand(1000000000, 9999999999);
514 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
515 $asset->setAttrValue(
'api_key', $new_key);
516 $asset->saveAttributes();
517 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
518 pre_echo(
'JS API Asset #'.$asset->id.
' has a new API key '.$new_key);
522 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
526 pre_echo(
'Updated - '.$count.
' Javascript Api(s)...');
527 pre_echo($asset_name.
' UPGRADE COMPLETE - TO VERSION 0.3');
531 if (version_compare($current_version,
'0.4',
'<')) {
533 pre_echo(
'STARTING UPGRADE - FROM VERSION '.$current_version.
' TO 0.4');
534 $root_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_folder');
535 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
537 pre_echo(
'Upgrading '.count($children).
' assets...');
538 foreach ($children as $assetid => $type) {
539 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $this->
getAssetType());
540 if (is_null($asset))
continue;
542 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'attributes')) {
543 trigger_localised_error(
'CMS0025', E_USER_WARNING,
'0.2', $asset->name, $asset->id);
548 $asset->setAttrValue(
'get_locks_info', FALSE);
550 $asset->setAttrValue(
'get_keywords_replacements', FALSE);
552 $asset->setAttrValue(
'set_asset_status', FALSE);
554 if (!$asset->saveAttributes()) {
555 trigger_localised_error(
'CMS0026', E_USER_WARNING,
'0.2');
559 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id,
'attributes');
561 pre_echo(
'UPGRADE COMPLETE - FROM VERSION '.$current_version.
' TO 0.4');
565 if (version_compare($current_version,
'0.5',
'<')) {
567 pre_echo(
'STARTING UPGRADE - FROM VERSION '.$current_version.
' TO 0.5');
568 $root_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_folder');
569 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
571 pre_echo(
'Upgrading '.count($children).
' assets...');
572 foreach ($children as $assetid => $type) {
573 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $this->
getAssetType());
574 if (is_null($asset))
continue;
576 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'attributes')) {
577 trigger_localised_error(
'CMS0025', E_USER_WARNING,
'0.5', $asset->name, $asset->id);
582 $asset->setAttrValue(
'get_web_path', FALSE);
584 $asset->setAttrValue(
'get_web_path', FALSE);
586 $asset->setAttrValue(
'force_simple_edit', FALSE);
588 $asset->setAttrValue(
'get_workflow_schema', FALSE);
591 if (!$asset->saveAttributes()) {
592 trigger_localised_error(
'CMS0026', E_USER_WARNING,
'0.5');
596 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id,
'attributes');
598 pre_echo(
'UPGRADE COMPLETE - FROM VERSION '.$current_version.
' TO 0.5');
602 if (version_compare($current_version,
'0.6',
'<')) {
604 pre_echo(
'STARTING UPGRADE - FROM VERSION '.$current_version.
' TO 0.6');
605 $root_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_folder');
606 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($root_folder->id, $this->getAssetType(), FALSE);
608 pre_echo(
'Upgrading '.count($children).
' assets...');
609 foreach ($children as $assetid => $type) {
610 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $this->
getAssetType());
611 if (is_null($asset))
continue;
613 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($asset->id,
'attributes')) {
614 trigger_localised_error(
'CMS0025', E_USER_WARNING,
'0.6', $asset->name, $asset->id);
618 $asset->setAttrValue(
'set_file_content', FALSE);
620 $asset->setAttrValue(
'import_assets', FALSE);
622 if (!$asset->saveAttributes()) {
623 trigger_localised_error(
'CMS0026', E_USER_WARNING,
'0.6');
627 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id,
'attributes');
629 pre_echo(
'UPGRADE COMPLETE - FROM VERSION '.$current_version.
' TO 0.6');