25 error_reporting(E_ALL);
26 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
28 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
29 if (empty($SYSTEM_ROOT)) {
30 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
34 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
35 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
39 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
42 echo
'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.
'": ';
44 $root_password = rtrim(fgets(STDIN, 4094));
48 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
49 if (!$root_user->comparePassword($root_password)) {
50 echo
"ERROR: The root password entered was incorrect\n";
53 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
54 trigger_error(
"Failed logging in as root user\n", E_USER_ERROR);
61 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
62 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
64 $sql =
'SELECT urlid, url, assetid FROM sq_ast_url';
68 foreach ($root_urls as $urlid => $url) {
69 echo $urlid.
'. '.$root_urls[$urlid][0][
'url'].
"\n";
76 while (!in_array($chosen_url, array_keys($root_urls))) {
77 $chosen_url = get_line(
'Please enter the urlid of the url to change: ');
78 if (!in_array($chosen_url, array_keys($root_urls))) {
79 echo
'Invalid urlid!'.
"\n";
83 $from_url = $root_urls[$chosen_url][0][
'url'];
84 $from_urlid = $chosen_url;
85 $from_site_assetid = $root_urls[$chosen_url][0][
'assetid'];
86 $to_url = get_line(
'Please enter the url to change to: ');
90 $system_root_urls = explode(
"\n", trim(SQ_CONF_SYSTEM_ROOT_URLS));
91 $matching_from_roots = Array();
92 $matching_roots = Array();
98 foreach ($system_root_urls as $root_url) {
99 if (substr($to_url.
'/', 0, strlen($root_url) + 1) == $root_url.
'/') {
100 $matching_roots[] = $root_url;
103 if (substr($from_url.
'/', 0, strlen($root_url) + 1) == $root_url.
'/') {
104 $matching_from_roots[] = $root_url;
108 if (empty($matching_roots)) {
109 echo
'The new URL entered, "'.$to_url.
'", is not based upon an existing System Root URL.'.
"\n";
110 $to_url = get_line(
'Please re-enter the new URL: ');
117 while ($confirm !=
'y' && $confirm !=
'n') {
118 $confirm = strtolower(get_line(
'Change '.$from_url .
' to '.$to_url.
' (y/n)? : '));
119 if ($confirm !=
'y' && $confirm !=
'n') {
120 echo
'Please answer y or n'.
"\n";
121 }
else if ($confirm ==
'n') {
127 foreach (Array(
'sq_ast_lookup_value',
'sq_ast_lookup') as $tablename) {
132 url = :to_url || SUBSTR(url, :from_url_length + 1)
134 url LIKE :from_url_wildcard';
136 if ($tablename ==
'sq_ast_lookup') {
137 $sql .=
' AND root_urlid = :from_urlid';
138 }
else if ($tablename ==
'sq_ast_lookup_value') {
139 $sql .=
' AND url IN (
145 sq_ast_lookup_value v ON ((l.url = v.url) OR (l.url || \'/\' = v.url))
147 l.root_urlid = :from_urlid
176 if (trim(SQ_CONF_STATIC_ROOT_URL) ==
'') {
179 $common_roots = array_intersect($matching_roots, $matching_from_roots);
180 $matching_roots = array_diff($matching_roots, $common_roots);
181 $matching_from_roots = array_diff($matching_from_roots, $common_roots);
182 $file_children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($from_site_assetid,
'file', FALSE);
184 $limit_clause = (strpos($db_type,
'oci') !== FALSE) ?
'AND ROWNUM = 1' :
'LIMIT 1';
187 for ($x = 0; $x < min(count($matching_roots), count($matching_from_roots)); $x++) {
189 $sql =
'UPDATE sq_ast_lookup_value SET url = :to_url || SUBSTR(url, :from_url_length + 1) WHERE url IN (SELECT url FROM sq_ast_lookup WHERE assetid IN (SELECT minorid FROM sq_ast_lnk WHERE linkid IN (SELECT linkid FROM sq_ast_lnk_tree t1 WHERE treeid LIKE (SELECT treeid || \'_%\' FROM sq_ast_lnk_tree t2 WHERE linkid IN (SELECT linkid FROM sq_ast_lnk WHERE minorid = :site_assetid) '.$limit_clause.
')))
190 AND url LIKE :from_url || \'/__data/%\')';
199 $sql =
'UPDATE sq_ast_lookup SET url = :to_url || SUBSTR(url, :from_url_length + 1) WHERE assetid IN (SELECT minorid FROM sq_ast_lnk WHERE linkid IN (SELECT linkid FROM sq_ast_lnk_tree t1 WHERE treeid LIKE (SELECT treeid || \'_%\' FROM sq_ast_lnk_tree t2 WHERE linkid IN (SELECT linkid FROM sq_ast_lnk WHERE minorid = :site_assetid) '.$limit_clause.
')))
200 AND url LIKE :from_url || \'/__data/%\'';
212 for (; $x < count($matching_roots); $x++) {
213 $sql =
'INSERT INTO sq_ast_lookup (url, root_urlid, http, https, assetid) SELECT DISTINCT :to_url || SUBSTR(url, STRPOS(url, \'/__data/\')), 0, http, https, assetid FROM sq_ast_lookup WHERE assetid IN (SELECT minorid FROM sq_ast_lnk WHERE linkid IN (SELECT linkid FROM sq_ast_lnk_tree t1 WHERE treeid LIKE (SELECT treeid || \'_%\' FROM sq_ast_lnk_tree t2 WHERE linkid IN (SELECT linkid FROM sq_ast_lnk WHERE minorid = :site_assetid) '.$limit_clause.
')))';
216 $sql = str_replace(
'STRPOS(',
'INSTR(', $sql);
225 for (; $x < count($matching_from_roots); $x++) {
227 $sql =
'DELETE FROM sq_ast_lookup_value WHERE url IN (SELECT url FROM sq_ast_lookup WHERE assetid IN (SELECT minorid FROM sq_ast_lnk WHERE linkid IN (SELECT linkid FROM sq_ast_lnk_tree t1 WHERE treeid LIKE (SELECT treeid || \'_%\' FROM sq_ast_lnk_tree t2 WHERE linkid IN (SELECT linkid FROM sq_ast_lnk WHERE minorid = :site_assetid) '.$limit_clause.
')))
228 AND url LIKE :from_url || \'/__data/%\')';
234 $sql =
'DELETE FROM sq_ast_lookup WHERE assetid IN (SELECT minorid FROM sq_ast_lnk WHERE linkid IN (SELECT linkid FROM sq_ast_lnk_tree t1 WHERE treeid LIKE (SELECT treeid || \'_%\' FROM sq_ast_lnk_tree t2 WHERE linkid IN (SELECT linkid FROM sq_ast_lnk WHERE minorid = :site_assetid) '.$limit_clause.
')))
235 AND url LIKE :from_url || \'/__data/%\'';
244 bam(
'LOOKUPS CHANGED FROM '.$from_url.
' TO '.$to_url);
246 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
247 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
257 function get_line($prompt=
'')
261 return rtrim(fgets(STDIN, 4096));