Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
file_bridge_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 bridge',
48  'update_fn' => '',
49  'is_admin' => '0',
50  ),
51  'path' => Array(
52  'added' => '0.1',
53  'type' => 'text',
54  'default' => '',
55  'description' => 'The path the bridge is responsible for',
56  ),
57  );
58 
59  }//end constructor
60 
61 
62 
71  function _upgrade($current_version)
72  {
73  parent::_upgrade($current_version);
74 
75  if (version_compare($current_version, '0.2', '<')) {
76  echo('UPGRADING SEARCH PAGE FROM '.$current_version."\n");
77  pre_echo('Updating File Bridge...');
78 
79  // all we care is removing the XML for "webpaths" screen
80  // so just do it
81  $file_for_webpath = SQ_DATA_PATH.'/private/asset_types/file_bridge/localised_screens/screen_paths.en';
82  if (is_file($file_for_webpath)) {
83  unlink($file_for_webpath);
84  }
85 
86  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
87  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
88 
89  // Get all File Bridge assets
90  $file_bridges = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('file_bridge', FALSE, TRUE);
91 
92  $count = 0;
93  foreach ($file_bridges as $id => $file_bridge) {
94  $bridge = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
95  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
96  if (!$bridge->saveWebPaths(Array(), FALSE)) {
97  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
98  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
99 
100  pre_echo('UPGRADE FAILED - Could not save webpaths');
101  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
102  return FALSE;
103  }
104  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($bridge, TRUE);
105  unset($bridge);
106  $count++;
107 
108  }//end foreach bridge
109 
110  pre_echo('Updated - '.$count.' File Bridge(s)...');
111 
112  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
113  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
114 
115 
116  pre_echo('FILE BRIDGES SUCCESSFULLY UPGRADED TO VERSION 0.2');
117  }//end if
118 
119 
120  if (version_compare($current_version, '0.3', '<')) {
121  $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(), 'name'));
122  // version 0.2 -> 0.3
123  pre_echo('STARTING '.$asset_name.' UPGRADE - TO VERSION 0.3');
124  $file_bridges = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE, TRUE);
125  $found = FALSE;
126  foreach ($file_bridges as $assetid => $type_code) {
127  $asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
128  if (is_null($asset)) continue;
129 
130  // We need to output our content files, otherwise old paint layouts will print blank
131  $path = $asset->attr('path');
132  if(!empty($path)) {
133  echo('Detected File Bridge asset #'.$asset->id.' with Path attribute "'.$asset->attr('path').'"'."\n");
134  $found = TRUE;
135  }
136 
137  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
138  unset($asset);
139 
140  }//end foreach
141 
142  if($found) {
143  echo ("\n");
144  echo ('******************************************************************************************************************'."\n");
145  echo ("Security Updates\n");
146  echo('Paths of above assets are now restored to "data/public" for security purposes'."\n");
147  echo('If old paths are required and considered safe, please configure '.SQ_DATA_PATH.'/private/conf/file_bridge.inc'."\n");
148  echo('******************************************************************************************************************'."\n");
149  }
150  pre_echo($asset_name.' UPGRADE COMPLETE - FROM VERSION '.$current_version.' TO 0.3');
151 
152  }//end version 0.3 upgrade
153 
154  return TRUE;
155 
156  }//end _upgrade()
157 
158 }//end class
159 
160 ?>