Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_folder_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
38  function Search_Folder_Management(&$pm)
39  {
40  $this->Asset_Management($pm);
41 
42  $this->vars = Array(
43  'name' => Array(
44  'added' => '0.2',
45  'type' => 'text',
46  'default' => '',
47  'is_admin' => FALSE,
48  'is_contextable'=> TRUE,
49  ),
50  'settings' => Array(
51  'added' => '0.1',
52  'type' => 'serialise',
53  'default' => Array(),
54  ),
55  );
56 
57  }//end constructor
58 
59 
68  function _upgrade($current_version)
69  {
70  if (!parent::_upgrade($current_version)) return FALSE;
71 
72  if (version_compare($current_version, '0.2', '<=')) {
73  // version 0.2->0.3 upgrade - sees $this->attr('settings')['types']
74  // being stored differently - as Array(typecode => inherits) instead
75  // of Array(typecode) - due to search manager upgrades
76  pre_echo('STARTING SEARCH FOLDER UPGRADE - VERSION 0.2 => 0.3');
77 
78  $children = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE);
79  foreach ($children as $assetid) {
80  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
81  $settings = $asset->attr('settings');
82 
83  // types have not been set at all?
84  if (!isset($settings['types'])) continue;
85  $types = $settings['types'];
86 
87  // types has nothing in it?
88  if (count($types) == 0) continue;
89 
90  // if the first element of types is a boolean, this is already
91  // been converted somehow
92  if (is_bool(reset($types))) continue;
93 
94  // flip the types array to get typecodes as keys, then set them
95  // to inherit types (as this was what Search Manager used to do)
96  $types = array_flip($types);
97  foreach ($types as $type_code => $value) {
98  $types[$type_code] = TRUE;
99  }
100 
101  $settings['types'] = $types;
102  $asset->setAttrValue('settings', $settings);
103 
104  if (!$asset->saveAttributes()) {
105  trigger_localised_error('SCH0009', E_USER_WARNING);
106  return FALSE;
107  }
108 
109  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
110  }//end foreach
111 
112  pre_echo('SEARCH FOLDER UPGRADE COMPLETE - VERSION 0.2 => 0.3');
113 
114  }//end if
115 
116  if (version_compare($current_version, '0.3', '<=')) {
117  // version 0.3->0.4 upgrade - changes to accept multiple root nodes.
118  // The variable $settings['root'] is now stored as an array of
119  // assetids, rather than a single value.
120  pre_echo('STARTING SEARCH FOLDER UPGRADE - VERSION 0.3 => 0.4');
121 
122  $children = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE);
123  foreach ($children as $assetid) {
124  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
125  $settings = $asset->attr('settings');
126 
127  // only need to save this attribute
128  if (!is_array($settings['root'])) {
129  $settings['root'] = (empty($settings['root'])) ? Array() : Array($settings['root']);
130  $asset->setAttrValue('settings', $settings);
131 
132  if (!$asset->saveAttributes()) {
133  trigger_localised_error('SCH0009', E_USER_WARNING);
134  return FALSE;
135  }
136  }
137 
138  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
139  $asset = NULL;
140  }
141 
142  pre_echo('SEARCH FOLDER UPGRADE COMPLETE - VERSION 0.3 => 0.4');
143 
144  }//end if
145 
146  return TRUE;
147 
148  }//end _upgrade()
149 
150 
151 }//end class
152 
153 ?>