Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
file_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  'added' => '0.1',
45  'type' => 'text',
46  'default' => '',
47  'description' => 'The name of the file (eg. myfile.zip)',
48  'update_fn' => '',
49  'is_admin' => '0',
50  ),
51  'allow_unrestricted' => Array(
52  'added' => '0.2',
53  'type' => 'boolean',
54  'default' => TRUE,
55  'description' => 'Allows the use of the __data URL if true',
56  'parameters' => Array('allow_empty' => FALSE),
57  'update_fn' => '',
58  ),
59  'title' => Array(
60  'added' => '0.3',
61  'type' => 'text',
62  'default' => '',
63  'is_admin' => '0',
64  'description' => 'Friendly name for the file',
65  'is_contextable' => TRUE,
66  ),
67  );
68 
69  }//end constructor
70 
71 
81  function _upgrade($current_version)
82  {
83  if (!parent::_upgrade($current_version)) return FALSE;
84 
85  if (version_compare($current_version, '0.4', '<')) {
86  pre_echo('UPGRADING FILE ASSETS - FROM VERSION '.$current_version);
87  $children = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE);
88  foreach ($children as $assetid) {
89  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
90  $attr = $asset->attr('title');
91  if (empty($attr)) {
92  $asset->setAttrValue('title', $asset->attr('name'));
93  $asset->saveAttributes();
94  }
95  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
96  }
97  }//end if version 0.4
98 
99  if (version_compare($current_version, '0.5', '<')) {
100  pre_echo('UPGRADING FILE ASSETS - FROM VERSION '.$current_version);
101  $where = 'type_code IN (
102  SELECT type_code
103  FROM sq_ast_typ_inhd
104  WHERE inhd_type_code = :type_code
105  )';
106  $where .= ' AND (status = \''.SQ_STATUS_EDITING.'\' OR status = \''.SQ_STATUS_EDITING_APPROVAL.'\' OR status = \''.SQ_STATUS_EDITING_APPROVED.'\')';
107  $sql = 'SELECT assetid FROM '.SQ_TABLE_RUNNING_PREFIX.'ast WHERE '.$where;
108  $query = MatrixDAL::preparePdoQuery($sql);
109  MatrixDAL::bindValueToPdo($query, 'type_code', $this->getAssetType());
110  $children = MatrixDAL::executePdoAssoc($query, 0);
111  if(!empty($children)) {
112  foreach ($children as $assetid) {
113  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
114  $url = $asset->getURL();
115  if(empty($asset)) continue;
116  if(empty($url)) continue;
117  pre_echo('FILE #'.$asset->id.' UPDATED');
118  $asset->updateLookups();
119  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
120  }
121  }
122  pre_echo('FILE ASSETS UPGRADE COMPLETE - VERSION 0.5');
123  }//end if version 0.5
124 
125  return TRUE;
126 
127  }//end _upgrade()
128 
129 
130 }//end class
131 ?>