Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
root_folder.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/folder/folder.inc';
19 
31 class Root_Folder extends Folder
32 {
33 
34 
41  function Root_Folder($assetid=0)
42  {
43  $this->Folder($assetid);
44 
45  }//end constructor
46 
47 
60  function create(&$link)
61  {
62  require_once SQ_CORE_PACKAGE_PATH.'/system/system_asset_fns.inc';
63  $this->_tmp[__CLASS__.'_in_create'] = TRUE;
64 
65  if (!system_asset_fns_create_pre_check($this)) {
66  return FALSE;
67  }
68 
69  $ret_val = parent::create($link);
70  if ($ret_val) {
71  if ($this->id != 1) {
72  throw new Exception('Unable to create root folder, as it did not receive asset ID #1. Fragments of another system may exist in the database; please ensure the database is clear of previous installations before installing.');
73  trigger_localised_error('CORE0077', E_USER_ERROR);
74  return FALSE;
75  }
76 
77  $db = DAL::getDb();
78 
79  $linkid = MatrixDAL::executeOne('core', 'seqNextVal', Array('seqName' => 'sq_ast_lnk_seq'));
80 
81  if ($linkid != 1) {
82  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
83  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
84  throw new Exception('Unable to create root folder, as it did not receive link ID #1. Fragments of another system may exist in the database; please ensure the database is clear of previous installations before installing.');
85  trigger_localised_error('CORE0078', E_USER_ERROR);
86  return FALSE;
87  }
88 
89  require_once SQ_FUDGE_PATH.'/db_extras/db_extras.inc';
90 
91  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db3');
92  $db = DAL::getDb();
93  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
94 
95  // right, we need to do some manipulation for the link table to put in some initial values
96  // so that the root folder, like everything else, has a link where it is a minor party
97  $sql = 'INSERT INTO
98  sq_ast_lnk
99  (
100  linkid,
101  majorid,
102  minorid,
103  link_type,
104  value,
105  sort_order,
106  is_dependant,
107  is_exclusive,
108  updated,
109  updated_userid
110  )
111  VALUES
112  (
113  :linkid,
114  :majorid,
115  :minorid,
116  :link_type,
117  :value,
118  :sort_order,
119  :is_dependant,
120  :is_exclusive,
121  :updated,
122  :updated_userid
123  )';
124 
125 
126  try {
127  $query = MatrixDAL::preparePdoQuery($sql);
128  MatrixDAL::bindValueToPdo($query, 'linkid', 1, PDO::PARAM_INT);
129  MatrixDAL::bindValueToPdo($query, 'majorid', 0, PDO::PARAM_INT);
130  MatrixDAL::bindValueToPdo($query, 'minorid', 1, PDO::PARAM_INT);
131  MatrixDAL::bindValueToPdo($query, 'link_type', SQ_LINK_TYPE_1, PDO::PARAM_INT);
132  MatrixDAL::bindValueToPdo($query, 'value', '', PDO::PARAM_STR);
133  MatrixDAL::bindValueToPdo($query, 'sort_order', 0, PDO::PARAM_INT);
134  MatrixDAL::bindValueToPdo($query, 'is_dependant', 1, PDO::PARAM_INT);
135  MatrixDAL::bindValueToPdo($query, 'is_exclusive', 1, PDO::PARAM_INT);
136  MatrixDAL::bindValueToPdo($query, 'updated', ts_iso8601(time()), PDO::PARAM_STR);
137  MatrixDAL::bindValueToPdo($query, 'updated_userid', 0, PDO::PARAM_STR);
138  // TODO: turn this into a PDO query
139  MatrixDAL::execPdoQuery($query);
140  } catch (Exception $e) {
141  throw new Exception('Unable to create root folder\'s link #1 entry due to database error: '.$e->getMessage());
142  }
143 
144 
145  $sql = 'INSERT INTO
146  sq_ast_lnk_tree
147  (
148  treeid,
149  linkid,
150  num_kids
151  )
152  VALUES
153  (
154  \'-\',
155  1,
156  0
157  )';
158 
159  try {
160  // TODO: turn this into a PDO query
161  MatrixDAL::executeSql($sql);
162  } catch (Exception $e) {
163  throw new Exception('Unable to create root folder\'s link tree entry due to database error: '.$e->getMessage());
164  }
165 
166  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
167  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
168 
169  if (!system_asset_fns_create_cleanup($this)) {
170  return FALSE;
171  }
172  }//end if
173 
174  unset($this->_tmp[__CLASS__.'_in_create']);
175  return $ret_val;
176 
177  }//end create()
178 
179 
189  function _getName($short_name=FALSE)
190  {
191  return ($short_name) ? '/' : translate('root_folder');
192 
193  }//end _getName()
194 
195 
202  function canDelete()
203  {
204  return FALSE;
205 
206  }//end canDelete()
207 
208 
215  function canClone()
216  {
217  return FALSE;
218 
219  }//end canClone()
220 
221 
231  function readAccess($assetids=Array())
232  {
233  return TRUE;
234 
235  }//end readAccess()
236 
237 
250  function _checkPermissionAccess($perm, $assetids=Array())
251  {
252  if (empty($assetids)) {
253  if ($GLOBALS['SQ_SYSTEM']->userRoot()) return TRUE;
254  if ($GLOBALS['SQ_SYSTEM']->userSystemAdmin()) {
255  return TRUE;
256  }
257  return FALSE;
258  } else {
259  return parent::_checkPermissionAccess($perm, $assetids);
260  }
261 
262  }//end _checkPermissionAccess()
263 
264 
274  function setAttrValue($name, $value)
275  {
276  if ($name == 'name' && empty($this->_tmp[__CLASS__.'_in_create'])) {
277  trigger_localised_error('CORE0112', E_USER_WARNING);
278  return FALSE;
279  }
280 
281  return parent::setAttrValue($name, $value);
282 
283  }//end setAttrValue()
284 
285 
286 }//end class
287 
288 ?>