Add/Remove URL Script

Last Updated: 17 Dec 2015

The add_remove_url.php script allows you to add or remove a URL from a Site asset and its children. You can also run this script to add or remove URLs from the Designs, Media, Web Services and Users system folders.

This script is located in the /home/websites/squiz_matrix/scripts directory and takes one parameter, the system root directory. Please note that you will be prompted to input additional information during the running of this script, such as the URL you want to add/remove.

Tip: You should backup your system before using this script.

Adding a URL

An example usage of this script when adding a URL is shown below. In this example, we are adding the URL www.example.com/new to our Site asset (#150).

$ php add_remove_url.php [system_root]

Enter the root password for "The System": ***** Please specify whether you want to 'add' or 'remove' a URL: add

------------------------------------
To use this script, you would need the following information

Site Assetid
Protocol to be used
New URL
An existing URL of the site

Make sure you have all you information you need before Proceeding

------------------------------------
Please specify whether this URL use HTTP protocol or not (1 or 0): 1
Please specify whether this URL use HTTPS protocol or not (1 or 0): 0
Enter the Site Assetid to apply the URL to: 150
Enter the New URL: www.example.com/new
Enter the existing URL: www.example.com/old

------------------------------------
INSERT INTO sq_ast_url (http, https, assetid, url, urlid) values (
                                    :http, :https, :assetid, :new_url, :new_urlid)
------------------------------------

------------------------------------
INSERT INTO sq_ast_lookup_value (url, name, value, depth)
                                        SELECT replace(url, :existing_url, :new_url), name, value, depth
                                            FROM sq_ast_lookup_value v
                                            WHERE
    (v.value IN
        (select k. minorid from sq_ast_lnk k where k.value = 'paint_layout::system::frontend' or k.value = 'override::paint_layout::system::frontend'
        and k.majorid in (select kk.majorid from sq_ast_lnk kk
               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))
    OR v.name like 'design%' or v.name like 'override::design%')
    AND rtrim(url, '/') in (SELECT url FROM sq_ast_lookup WHERE root_urlid = :existing_urlid)
------------------------------------

------------------------------------
INSERT INTO sq_ast_lookup (http, https, assetid, url, root_urlid)
                                        SELECT :http, :https, assetid, replace(url, :existing_url, :new_url), :new_urlid
                                        FROM sq_ast_lookup WHERE url like :existing_url_wildcard AND root_urlid = :existing_urlid

Removing a URL

An example usage of this script when removing a URL is shown below. In this example, we are remove the URL www.example.com/old from the Sites in our system.

$ php add_remove_url.php [system_root]

Enter the root password for "The System": password
Please specify whether you want to 'add' or 'remove' a URL: remove

------------------------------------
!Important: Please make sure that you know how to use this script, and remember to back up the database before proceeding

(Press Ctrl+C to terminate the script)

------------------------------------
Enter the URL to be removed: www.example.com/old

------------------------------------
DELETE FROM sq_ast_lookup_value WHERE url like 'www.example.com/old%'
------------------------------------

------------------------------------
DELETE FROM sq_ast_lookup WHERE root_urlid = '11' AND url like 'www.example.com/old%'
------------------------------------

------------------------------------
DELETE FROM sq_ast_url WHERE urlid = '11' AND url like 'www.example.com/old'

Previous Chapter Next Chapter