Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
url_manager.inc
1 <?php
27 {
28 
29  //static $db = $GLOBALS['SQ_SYSTEM']->db;
30  function URL_Manager()
31  {
32 
33  }//end constructor
34 
35 
36  /*
37  * Interface to add URL
38  *
39  */
40  public static function cliInterfaceAddUrl()
41  {
42  global $SYSTEM_ROOT;
43  pre_echo("To use this script, you would need the following information\n
44 Site Assetid
45 Protocol to be used
46 New URL
47 An existing URL of the site\n
48 Make sure you have all you information you need before Proceeding\n");
49 
50  $http = -1;
51  while ($http != '0' && $http != '1') {
52  $http = get_line('Please specify whether this URL use HTTP protocol or not (1 or 0): ');
53  }
54 
55  $https = -1;
56  while ($https != '0' && $https != '1') {
57  $https = get_line('Please specify whether this URL use HTTPS protocol or not (1 or 0): ');
58  }
59 
60  if ($http != 1 && $https != 1) {
61  echo "Please select either HTTP or HTTPS as protocol\n";
62  exit(0);
63  }
64 
65 
66  $assetid = NULL;
67  while (is_null($assetid)) {
68  $assetid = get_line('Enter the Site Assetid to apply the URL to: ');
69  assert_valid_assetid($assetid);
70 
71  $asset = self::checkAssetTypes($assetid);
72  if (!$asset) {
73  echo "Asset must be either a site, design folder, media folder, or user folder\n";
74  $assetid = NULL;
75  }//end if
76 
77  }//end while
78 
79 
80  // Now we have to check whether we should add this URL to this site or not.
81  require_once $SYSTEM_ROOT.'/data/private/conf/main.inc';
82 
83  $update_file_public_live_assets = FALSE;
84  $new_url = NULL;
85  while (is_null($new_url)) {
86  $new_url = get_line('Enter the New URL:');
87 
88  if (!(self::checkNewUrlExists($new_url))) {
89  echo "The new URL : ".$new_url." is already exist.\n";
90  $new_url = NULL;
91  continue;
92  }//end if
93 
94  if (!(self::checkNewUrlInSystemRootUrls($SYSTEM_ROOT, $new_url, $update_file_public_live_assets))) {
95  echo "The provided URL is not based upon an existing System Root URL\n";
96  echo "Existing System Root URLs are : \n".SQ_CONF_SYSTEM_ROOT_URLS."\n";
97  $new_url = NULL;
98  continue;
99  }//end if
100 
101  }//end while
102 
103  $existing_url = NULL;
104  while (is_null($existing_url)) {
105  $existing_url = get_line('Enter the existing URL: ');
106  }
107 
108  if ($new_url == $existing_url) {
109  echo "Does not allow to alter existing url\n";
110  exit(0);
111  }
112 
113  $site_urls = Array();
114  $urls = $asset->getURLs();
115  foreach ($urls as $url_info) {
116  $site_urls[] = $url_info['url'];
117  }
118  if (!in_array($existing_url, $site_urls)) {
119  echo "The existing URL does not belong to the site with id: $assetid \n";
120  exit(0);
121  }//end if
122 
123 
124  $existing_urlid = self::checkExistingUrlExists($existing_url);
125  if (!$existing_urlid) {
126  echo "The existing URL : ".$existing_url." does not exist\n";
127  exit(0);
128  }//end if
129 
130 
131  $inputs = Array (
132  'http' => $http,
133  'https' => $https,
134  'new_url' => $new_url,
135  'existing_url' => $existing_url,
136  'siteid' => $assetid,
137  'update_file_public_live_assets' => $update_file_public_live_assets,
138  'existing_urlid' => $existing_urlid[0]['urlid'],
139  );
140  return $inputs;
141 
142  }//end cliInterfaceAddUrl()
143 
144 
145  /*
146  * This function add URL for a site type asset
147  *
148  *
149  */
150  public static function addUrl($http, $https, $new_url, $existing_url, $assetid, $update_file_public_live_assets, $existing_urlid, $SYSTEM_ROOT, $quiet=FALSE)
151  {
152  // strip trailing slash
153  $new_url = strip_url($new_url);
154 
155  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
156 
157  // Lets check if the system is using static URL, if they use static URL, there's no point updating FILE PUBLIC LIVE assets.
158  $static_root_url = SQ_CONF_STATIC_ROOT_URL;
159  if (!empty($static_root_url)) {
160  $update_file_public_live_assets = FALSE;
161  }
162 
163  // First we check that the new URL being added is not under any system root URLs, if it is, we don't need to update this FILE PUBLIC LIVE assets.
164  if ($update_file_public_live_assets) {
165 
166  // Before we do any of the processing, lets grab all the FILE assets that are LIVE, and have PUBLIC READ ACCESS.
167  $asset_types_list_info = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeHierarchy('file');
168 
169  $asset_types_list = Array();
170  self::getTypeListRecursive($asset_types_list_info, $asset_types_list);
171 
172  $asset_types_list[] = 'file';
173  $children = Array();
174  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($assetid, $asset_types_list, TRUE);
175 
176 
177  // Remove shadow assets, they are not required for this purpose
178  foreach ($children as $id => $content) {
179  if(strpos($id,':')){
180  unset($children[$id]);
181  }
182  }
183 
184  $children = array_keys($children); // We just need the asset id
185  $public_user_id = 7;
186  $children_to_update = Array();
187  foreach ($children as $child_id) {
188  $child_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($child_id);
189  if ($child_asset->usePublicPath()) {
190  $children_to_update[] = MatrixDAL::quote((string) $child_id);
191  }//end if
192  // Else just ignore this asset
193  }//end foreach
194  }
195 
196  $new_urlid = MatrixDAL::executeOne('core', 'seqNextVal', Array('seqName' => 'sq_ast_url_seq'));
197 
198  $sql_update_sq_ast_url = 'INSERT INTO sq_ast_url (http, https, assetid, url, urlid) values (
199  :http, :https, :assetid, :new_url, :new_urlid)';
200 
201 
202  // Copy lookup value from existing url for new url.
203  //These urls have to be restricted to 1. both paint_layout and override paint layout which are asset based (not URL specified).
204  // 2. or Design look up
205  $sql_update_sq_ast_lookup_value =
206 
207  'INSERT INTO sq_ast_lookup_value (url, name, value, depth)
208  SELECT replace(url, :existing_url, :new_url), name, value, depth
209  FROM sq_ast_lookup_value v
210  WHERE
211  (v.value IN
212  (select k. minorid from sq_ast_lnk k where k.value = \'paint_layout::system::frontend\' or k.value = \'override::paint_layout::system::frontend\'
213  and k.majorid in (select kk.majorid from sq_ast_lnk kk
214  where kk.majorid = (select l.assetid from sq_ast_lookup l where l.url = v.url OR l.url || \'/\' = v.url) and kk.minorid = v.value))
215  OR v.name like \'design%\' or v.name like \'override::design%\')
216  AND rtrim(url, \'/\') in (SELECT url FROM sq_ast_lookup WHERE root_urlid = :existing_urlid)';
217 
218 
219 
220 
221 
222  $sql_update_sq_ast_lookup = 'INSERT INTO sq_ast_lookup (http, https, assetid, url, root_urlid)
223  SELECT :http, :https, assetid, replace(url, :existing_url, :new_url), :new_urlid
224  FROM sq_ast_lookup WHERE url like :existing_url_wildcard AND root_urlid = :existing_urlid';
225 
226  $sql_update_sq_ast_lookup_public = 'UPDATE sq_ast_lookup set root_urlid = 0 WHERE url like :new_url_wildcard AND url like :data_url AND root_urlid = :new_urlid';
227 
228  // Now we run the query
229  // 1. Add entry to sq_ast_url
230  $query = MatrixDAL::preparePdoQuery($sql_update_sq_ast_url);
231  MatrixDAL::bindValueToPdo($query, 'http', $http);
232  MatrixDAL::bindValueToPdo($query, 'https', $https);
233  MatrixDAL::bindValueToPdo($query, 'assetid', $assetid);
234  MatrixDAL::bindValueToPdo($query, 'new_url', $new_url);
235  MatrixDAL::bindValueToPdo($query, 'new_urlid', $new_urlid);
236  MatrixDAL::execPdoQuery($query);
237 
238  // 2. Add entries to sq_ast_lookup_value
239  $query = MatrixDAL::preparePdoQuery($sql_update_sq_ast_lookup_value);
240  MatrixDAL::bindValueToPdo($query, 'existing_url', $existing_url);
241  MatrixDAL::bindValueToPdo($query, 'new_url', $new_url);
242  MatrixDAL::bindValueToPdo($query, 'existing_urlid', $existing_urlid);
243  MatrixDAL::execPdoQuery($query);
244 
245  // 3, Add entries to sq_ast_lookup
246  $query = MatrixDAL::preparePdoQuery($sql_update_sq_ast_lookup);
247  MatrixDAL::bindValueToPdo($query, 'http', $http);
248  MatrixDAL::bindValueToPdo($query, 'https', $https);
249  MatrixDAL::bindValueToPdo($query, 'existing_url', $existing_url);
250  MatrixDAL::bindValueToPdo($query, 'existing_url_wildcard', $existing_url.'%');
251  MatrixDAL::bindValueToPdo($query, 'new_url', $new_url);
252  MatrixDAL::bindValueToPdo($query, 'new_urlid', $new_urlid);
253  MatrixDAL::bindValueToPdo($query, 'existing_urlid', $existing_urlid);
254  MatrixDAL::execPdoQuery($query);
255 
256  if (!$quiet) {
257  pre_echo($sql_update_sq_ast_url);
258  pre_echo($sql_update_sq_ast_lookup_value);
259  pre_echo($sql_update_sq_ast_lookup);
260  }//end if
261 
262  $query = MatrixDAL::preparePdoQuery($sql_update_sq_ast_lookup_public);
263  MatrixDAL::bindValueToPdo($query, 'new_url_wildcard', $new_url.'%');
264  MatrixDAL::bindValueToPdo($query, 'data_url', '%/__data/%');
265  MatrixDAL::bindValueToPdo($query, 'new_urlid', $new_urlid);
266  MatrixDAL::execPdoQuery($query);
267 
268  // We have done updating regular asset, now we will update the publically served file assets.
269 
270  if (!defined(SQ_CONF_SYSTEM_ROOT_URLS)) {
271  require_once $SYSTEM_ROOT.'/data/private/conf/main.inc';
272  }//end if
273  $root_urls = explode("\n", SQ_CONF_SYSTEM_ROOT_URLS);
274  if ($update_file_public_live_assets) {
275  // Now we have to chop out the system root Url from the "existing" Url.
276  $absolute_root = '';
277  $relative_root = '';
278  foreach ($root_urls as $url) {
279  if (strpos($existing_url, $url) !== FALSE) {
280  $relative_root = $url;
281  }
282  if ($existing_url == $url) {
283  $absolute_root = $url;
284  break;
285  }
286  }
287  $existing_url_public = (empty($absolute_root)) ? $relative_root : $absolute_root;
288 
289  // Now we have to chop out the system root Url from the "new" Url.
290  $absolute_new_root = '';
291  $relative_new_root = '';
292  foreach ($root_urls as $url) {
293  if (strpos($new_url, $url) !== FALSE) {
294  $relative_new_root = $url;
295  }
296  if ($new_url == $url) {
297  $absolute_new_root = $url;
298  break;
299  }
300  }
301  $new_url_public = (empty($absolute_new_root)) ? $relative_new_root : $absolute_new_root;
302 
303  // Do we have any file need to be updated?
304  if (!empty($children_to_update)) {
305  $in_clauses = Array();
306  foreach (array_chunk($children_to_update, 999) as $chunk) {
307  $in_clauses[] = ' assetid IN ('.implode(', ', $chunk).')';
308  }
309 
310  $count = 1;
311  $num_children_to_update = count($children_to_update);
312  foreach ($in_clauses as $condition) {
313  $sql_update_sq_ast_lookup_public_file = 'INSERT INTO sq_ast_lookup (http, https, assetid, url, root_urlid)
314  SELECT :http, :https, assetid, replace(url, :existing_url, :new_url), 0
315  FROM sq_ast_lookup WHERE root_urlid = 0 AND '. $condition. ' AND url like :existing_url_wildcard';
316  $added_condition = ' AND replace(url, :existing_url_1, :new_url_1) NOT IN (
317  SELECT url from sq_ast_lookup WHERE root_urlid = 0 AND '. $condition. ' AND url like replace(url,:existing_url_2, :new_url_2))';
318 
319  $sql_update_sq_ast_lookup_public_file .= $added_condition;
320 
321  // If the last char is not "/" we'l add a slash to make sure if we have two overlap url we still can handle it.
322  // Eg: charlie.squiz.net/hnguyen_3_18_0
323  // charlie.squiz.net/hnguyen_3_18_0_sr2 . These 2 Urls overlap each other, so the replace() wont work unless we add "/"
324  if ($existing_url_public[strlen($existing_url_public)-1] != '/') {
325  $existing_url_public .= '/';
326  }//end if
327  // If we add slash "/" for existing url we need to add to the new url too
328  if ($new_url_public[strlen($new_url_public)-1] != '/') {
329  $new_url_public .= '/';
330  }//end if
331 
332  if (!$quiet) pre_echo($sql_update_sq_ast_lookup_public_file);
333  $query = MatrixDAL::preparePdoQuery($sql_update_sq_ast_lookup_public_file);
334  MatrixDAL::bindValueToPdo($query, 'http', $http);
335  MatrixDAL::bindValueToPdo($query, 'https', $https);
336  MatrixDAL::bindValueToPdo($query, 'existing_url', $existing_url_public);
337  MatrixDAL::bindValueToPdo($query, 'existing_url_1', $existing_url_public);
338  MatrixDAL::bindValueToPdo($query, 'existing_url_2', $existing_url_public);
339  MatrixDAL::bindValueToPdo($query, 'existing_url_wildcard', $existing_url_public.'%');
340  MatrixDAL::bindValueToPdo($query, 'new_url', $new_url_public);
341  MatrixDAL::bindValueToPdo($query, 'new_url_1', $new_url_public);
342  MatrixDAL::bindValueToPdo($query, 'new_url_2', $new_url_public);
343  MatrixDAL::execPdoQuery($query);
344  if (!$quiet) {
345  echo "\n Finished Updating ".(($count*1000 > $num_children_to_update) ? $num_children_to_update : $count*1000) ." files out of ".$num_children_to_update."\n";
346  }//end if
347  $count++;
348  }//end foreach
349 
350  }
351  }
352 
353  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
354 
355  }//end addUrl()
356 
357 
362  public static function cliInterfaceRemoveUrl()
363  {
364  global $SYSTEM_ROOT;
365  // For Removing, need to take in
366  // -removeurl
367  pre_echo("!Important: Please make sure that you know how to use this script, and remember to back up the database before proceeding\n
368 (Press Ctrl+C to terminate the script)\n");
369 
370  $remove_url = NULL;
371  while (is_null($remove_url)) {
372  $remove_url = get_line('Enter the URL to be removed: ');
373  }//end while
374 
375  $remove_url_info = self::checkExistingUrlExists($remove_url);
376  if ($remove_url_info === FALSE) {
377  echo 'The provided URL : '.$remove_url.' does not exist';
378  exit(0);
379  }//end if
380 
381  $remove_urlid = $remove_url_info[0]['urlid'];
382  $remove_assetid = $remove_url_info[0]['assetid'];
383 
384  return Array (
385  'remove_urlid' => $remove_urlid,
386  'remove_assetid' => $remove_assetid,
387  'remove_url' => $remove_url,
388  );
389 
390  }//end cliInterfaceRemoveUrl()
391 
392 
393  /*
394  * Function removeURL
395  *
396  *
397  */
398  public static function removeUrl($remove_urlid, $remove_assetid, $remove_url, $quiet=FALSE, $SYSTEM_ROOT)
399  {
400  global $db;
401 
402  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
403 
404  // Find all other root_urlid that look like $remove_url.'%', we don't want to remove those.
405  $sql_get_sub_url_root_urlid = 'SELECT url FROM sq_ast_url WHERE
406  url NOT LIKE :remove_url AND
407  url LIKE :remove_url_wildcard';
408 
409  $query = MatrixDAL::preparePdoQuery($sql_get_sub_url_root_urlid);
410  MatrixDAL::bindValueToPdo($query, 'remove_url', $remove_url);
411  MatrixDAL::bindValueToPdo($query, 'remove_url_wildcard', $remove_url.'%');
412  $avoid_urls = MatrixDAL::executePdoAssoc($query);
413 
414  // Before we do any of the processing, lets grab all the FILE assets that are LIVE, and have PUBLIC READ ACCESS.
415  $asset_types_list_info = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeHierarchy('file');
416 
417  $asset_types_list = Array();
418  self::getTypeListRecursive($asset_types_list_info, $asset_types_list);
419 
420  $asset_types_list[] = 'file';
421  $children = Array();
422  $children = $GLOBALS['SQ_SYSTEM']->am->getChildren($remove_assetid, $asset_types_list, TRUE);
423 
424  // Remove shadow assets, they are not required for this purpose
425  foreach ($children as $id => $content) {
426  if(strpos($id,':')){
427  unset($children[$id]);
428  }
429  }
430 
431  $children = array_keys($children); // We just need the asset id
432  $public_user_id = 7;
433  $children_to_update = Array();
434 
435  foreach ($children as $child_id) {
436  $child_asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($child_id);
437  if ($child_asset->usePublicPath()) {
438  $get_count_links_query = 'SELECT COUNT(*) FROM sq_ast_lnk WHERE minorid = '.MatrixDAL::quote($child_id);
439  $count = MatrixDAL::executeSqlOne($get_count_links_query);
440  // We are only calling getParents if this asset is linked in multiple places
441  if ($count > 1) {
442  $site_parents = $GLOBALS['SQ_SYSTEM']->am->getParents($child_id, 'site', FALSE);
443  // If we have more than 1 site as parent, potential multiple URLs, so we are not going to delete the __data URL.
444  if (!(count($site_parents) > 1)) {
445  // We just have 1 site parent
446  $children_to_update[] = MatrixDAL::quote($child_id);
447  }//end if
448  } else {
449  $children_to_update[] = MatrixDAL::quote($child_id);
450  }//end else
451  }//end if
452  // Else just ignore this asset
453  }//end foreach
454 
455 
456  if (!empty($children_to_update)) {
457  $in_clauses = Array();
458  foreach (array_chunk($children_to_update, 999) as $chunk) {
459  $in_clauses[] = ' assetid IN ('.implode(', ', $chunk).')';
460  }
461 
462  require_once $SYSTEM_ROOT.'/data/private/conf/main.inc';
463  $root_urls = Array();
464  $root_urls = explode("\n", SQ_CONF_SYSTEM_ROOT_URLS);
465 
466  // Now we have to chop out the system root Url from the "existing" Url.
467  $absolute_root_remove = '';
468  $relative_root_remove = '';
469  foreach ($root_urls as $url) {
470  if (strpos($remove_url, $url) !== FALSE) {
471  $relative_root_remove = $url;
472  }
473  if ($remove_url == $url) {
474  $absolute_root_remove = $url;
475  break;
476  }
477  }
478 
479  $remove_url_public = (empty($absolute_root_remove)) ? $relative_root_remove : $absolute_root_remove;
480 
481  $count = 1;
482  $num_children_to_update = count($children_to_update);
483  foreach ($in_clauses as $condition) {
484 
485  $sql_update_sq_ast_lookup_public = 'DELETE FROM sq_ast_lookup WHERE root_urlid = 0 AND url LIKE :remove_url_wildcard AND url LIKE :data_url';
486  $sql_update_sq_ast_lookup_public .= ' AND '.$condition;
487 
488  foreach ($avoid_urls as $index => $data) {
489  $sql_update_sq_ast_lookup_public .= ' AND url NOT LIKE ' . MatrixDAL::quote($data['url'].'%');
490  }//end foreach
491 
492  if (!$quiet) pre_echo($sql_update_sq_ast_lookup_public);
493  $query = MatrixDAL::preparePdoQuery($sql_update_sq_ast_lookup_public);
494  MatrixDAL::bindValueToPdo($query, 'remove_url_wildcard', $remove_url_public.'%');
495  MatrixDAL::bindValueToPdo($query, 'data_url', '%/__data/%');
496  MatrixDAL::execPdoQuery($query);
497 
498  if (!$quiet) {
499  echo "\n Finished deleting ".(($count*1000 > $num_children_to_update) ? $num_children_to_update : $count*1000) ." files out of ".$num_children_to_update;
500  }//end if
501  $count++;
502  }//end foreach
503 
504  }//end if
505 
506  $sql_update_sq_ast_lookup_value = 'DELETE FROM sq_ast_lookup_value WHERE url like '.MatrixDAL::quote($remove_url.'%');
507  foreach ($avoid_urls as $index => $data) {
508  $sql_update_sq_ast_lookup_value .= ' AND url NOT LIKE ' . MatrixDAL::quote($data['url'].'%');
509  }//end foreach
510 
511  $sql_update_sq_ast_lookup = 'DELETE FROM sq_ast_lookup WHERE root_urlid = '.MatrixDAL::quote($remove_urlid).' AND url like '.MatrixDAL::quote($remove_url.'%').'';
512 
513  foreach ($avoid_urls as $index => $data) {
514  $sql_update_sq_ast_lookup .= ' AND url NOT LIKE ' . MatrixDAL::quote($data['url'].'%');
515  }//end foreach
516 
517  $sql_update_sq_ast_url = 'DELETE FROM sq_ast_url WHERE urlid = '.MatrixDAL::quote($remove_urlid).' AND url like '.MatrixDAL::quote($remove_url).'';
518 
519  // We run the query in different order
520  // 1. Remove entries in sq_ast_lookup_value
521  // 2. Remove entries in sq_ast_lookup
522  // 3. Remove the entry in sq_ast_url
523  MatrixDAL::executeSql($sql_update_sq_ast_lookup_value);
524  MatrixDAL::executeSql($sql_update_sq_ast_lookup);
525  MatrixDAL::executeSql($sql_update_sq_ast_url);
526 
527  if (!$quiet) {
528  pre_echo($sql_update_sq_ast_lookup_value);
529  pre_echo($sql_update_sq_ast_lookup);
530  pre_echo($sql_update_sq_ast_url);
531  }//end if
532 
533  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
534 
535  }//end removeURL()
536 
537 
542  private static function checkAssetTypes($assetid)
543  {
544  $allow_asset_types = array_keys($GLOBALS['SQ_SYSTEM']->am->getAssetTypeHierarchy('web_folder', 'system'));
545  $allow_asset_types[] = 'site';
546  $asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
547  if (!in_array($asset->type(), $allow_asset_types)) {
548  return FALSE;
549  }//end if
550  return $asset;
551 
552  }//end checkAssetTypes
553 
554 
559  public static function checkExistingUrlExists($existing_url)
560  {
561  $sql_check_existing_url = 'SELECT urlid, assetid FROM sq_ast_url WHERE url LIKE :existing_url';
562 
563  $query = MatrixDAL::preparePdoQuery($sql_check_existing_url);
564  MatrixDAL::bindValueToPdo($query, 'existing_url', $existing_url);
565  $existing_urlid = MatrixDAL::executePdoAll($query);
566  if (empty($existing_urlid)) {
567  return FALSE;
568  }//end if
569  return $existing_urlid;
570 
571  }//end checkExistingUrlExists()
572 
573 
574  /*
575  * This function check whether the new Url being added is allowed, ie whether there it is belong to the system roots list.
576  *
577  */
578  private static function checkNewUrlInSystemRootUrls($system_root, $new_url, &$update_file_public_live_assets)
579  {
580  require_once $system_root.'/data/private/conf/main.inc';
581  $update_file_public_live_assets = FALSE;
582  $root_urls = Array();
583 
584  $root_urls = explode("\n", SQ_CONF_SYSTEM_ROOT_URLS);
585  $in_root_urls = FALSE;
586  $root_urls_string = '';
587  foreach ($root_urls as $root_url) {
588  $root_urls_string .= $root_url."\n";
589  if (strpos($new_url, $root_url) === 0) {
590  $in_root_urls = TRUE;
591  // cut trailing slash if there's any
592  // only if new url is the same as one of the root url, or new url belongs to one of the root url.
593  if (($new_url == $root_url) || (strpos($new_url, $root_url) === 0 && strlen($new_url) > strlen($root_url))){
594  $update_file_public_live_assets = TRUE;
595  }//end if
596  }//end if
597 
598  }//end foreach
599 
600  if (!$in_root_urls) {
601  return FALSE;
602  }//end if
603 
604  return TRUE;
605 
606  }//end checkNewUrl()
607 
608 
609  /*
610  * This function check if the new Url is already exist in the system
611  *
612  */
613  private static function checkNewUrlExists($new_url)
614  {
615  //Does any asset have same URL?
616  $asset = $GLOBALS['SQ_SYSTEM']->am->getAssetFromURL(NULL, strip_url($new_url), TRUE, TRUE);
617  if($asset != NULL) return FALSE;
618 
619  $sql_check_new_url = 'SELECT url FROM sq_ast_url WHERE url = :new_url';
620 
621  $query = MatrixDAL::preparePdoQuery($sql_check_new_url);
622  MatrixDAL::bindValueToPdo($query, 'new_url', strip_url($new_url));
623  $new_url_check = MatrixDAL::executePdoOne($query);
624  if (!empty($new_url_check)) {
625  return FALSE;
626  }//end if
627 
628  return TRUE;
629 
630  }//end checkNewUrlExists()
631 
632 
636  private static function getTypeListRecursive($asset_types_list_info, &$asset_types_list)
637  {
638  foreach ($asset_types_list_info as $asset_type => $type_info)
639  {
640  $asset_types_list[] = $asset_type;
641  if (isset($type_info['subs'])) {
642  self::getTypeListRecursive($type_info['subs'], $asset_types_list);
643  }//end if
644  }//end foreach
645 
646  }//end getTypeListRecursive()
647 
648 
649 }//end class