System integrity scripts

system_integrity_check_indexes.php

The system_integrity_check_indexes.php script checks the Matrix database for any missing indexes. If missing indexes are found, this script will print an SQL query to run.

The script will not automatically run returned SQL queries as any found issues may require a manual fix.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

Example
$ php system_integrity_check_indexes.php [system_root]

------------------------------------
Checking Indexes
------------------------------------
Checking table sq_cal_date_val for a primary key            [ OK ]
Checking table sq_rb_cal_date_val for a primary key         [ OK ]
Checking table sq_hit_count for a primary key               [ OK ] ...

Checking for index sq_sch_idx_type                          [ OK ]
Checking for index sq_sch_idx_component                     [ OK ]
Checking for index sq_sch_idx_contextid                     [ OK ]

------------------------------------
 Checking locale settings
------------------------------------

------------------------------------
Check complete
------------------------------------

------------------------------------
Everything has been checked and no problems were found.
------------------------------------...

The system_integrity_check_links.php script checks all hyperlinks to another asset (referenced as ./?a=xx) inside a WYSIWYG editor (for example, a standard page) link to an existing asset. It highlights any asset that does not exist. You can then go to the content of the relevant asset within Matrix and fix the broken link.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

Example
$ php system_integrity_check_links.php [system_root]
WARNING: You are running this integrity checker on the whole system.
This is fine but it may take a long time

YOU HAVE 5 SECONDS TO CANCEL THIS SCRIPT...
1 2 3 4 5

WYSIWYG #30 - LINK #3276      [ INVALID ]

system_integrity_clean_cache_dir.php

The system_integrity_clean_cache_dir.php script deletes any expired cache files in the cache directory of Matrix.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

system_integrity_clean_old_files.php

The system_integrity_clean_old_files.php script checks for, and optionally deletes, files in the data directory that do not belong to an asset any more (orphaned files).

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • --delete-orphans (optional).

The system_integrity_content_links.php script verifies and updates asset reference links for images or files in Bodycopy contents. This script locks each asset as it updates it and also makes changes to the Matrix file system. It displays a Failed message for any asset that fails.

This script is for troubleshooting purposes and should only be run if you are experiencing problems with your system.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

Example
$ php system_integrity_content_links.php [system_root]
WARNING: You are running this integrity checker on the whole system.
This is fine but:
   it may take a long time; and
   it will acquire locks on many of your assets (meaning you wont be able to edit
   content for a while)

Container #22         [ OK ]
Container #26         [ OK ]

system_integrity_deleted_user_perms.php

The system_integrity_deleted_user_perms.php script deletes permissions that exist for deleted or non-existent users. For example, if an LDAP user is removed from the LDAP server, it does not notify Matrix, and hence the permissions for that user are not updated.

This script is for troubleshooting purposes and should only be run if you are experiencing problems with your system.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

Example
$ php system_integrity_deleted_user_perms.php [system_root]
WARNING: You are running this integrity checker on the whole system.
This is fine but:
  it may take a long time; and
  it will acquire locks on many of your assets (meaning you wont be able to
   edit content for a while)

Cleaning up permissions...
Root User [ # 12 ]           [ OK ]
Test User [ # 44 ]           [ OK ]
Unknown Asset [ # 5001 ]     [ FIXED ]
Unknown Asset [ # 5002 ]     [ FIXED ]
Public User [ # 7 ]          [ OK ]

Cleaning up roles...
Unknown Asset [ # 5001 ]     [ FIXED ]

system_integrity_fix_duplicate_rollback_entries.php

The system_integrity_fix_duplicate_rollback_entries.php script is used to report and fix any overlapping (and thus duplicate) entries in the rollback table, determined by an entry’s eff_to date value.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

-s <system_root>

The root directory of your system.

--show-records

Specifies to show any overlapping rollback table entries found (optional).

--fix-table=<table_name>

Fixes the overlapping rollback entries in the specified table. Use all to fix overlapping entries in all tables (optional).

Example
$ php scripts/system_integrity_fix_duplicate_rollback_entries.php -s <SYSTEM_ROOT> --show-records --fix-table=all

IMPORTANT: You have selected the option to fix the duplicate rollback entries from the Rollback table "sq_rb_ast_attr_val"
This will remove all duplicate entries in the table(s) except the one with the oldest "eff_from" date in the duplicate entries set.
Backing up db is recommended before running this script.
Are you sure you want to proceed (Y/n)? Y

Checking table sq_rb_ast ...
[ OK ]
Checking table sq_rb_ast_lnk ...
[OK]
Checking table sq_rb_shdw_ast_lnk ...
[ OK ]
Checking table sq_rb_ast_lnk_tree ...
[ OK ]
Checking table sq_rb_ast_attr_val ...
2 set(s) of overlapping entries found.
------------------------------------
0 => array (
    "assetid" => "260",
    "attrid" => "3081",
    "contextid" => "0",
    "sq_eff_to" => "2013-06-18 10:26:28",
    "occ" => "2"
),
1 => array (
    "assetid" => "260",
    "attrid" => "3081",
    "contextid" => "1",
    "sq_eff_to" => "2013-06-18 10:26:28",
    "occ" => "2"
)

------------------------------------
[ NOT OK ]
Fixing the rollback table sq_rb_ast_attr_val [ FIXED ]

Checking table sq_rb_ast_attr_uniq_val ...
[ OK ]
Checking table sq_rb_ast_url ...
[ OK ]
Checking table sq_rb_ast_path ...
[ OK ]
Checking table sq_rb_ast_lookup ...
[ OK ]
Checking table sq_rb_ast_lookup_value ...
[ OK ]
Checking table sq_rb_ast_lookup_remap ...
[ OK ]
Checking table sq_rb_ast_perm ...
[ OK ]
Checking table sq_rb_ast_edit_access ...
[ OK ]
Checking table sq_rb_ast_mdata ...
[ OK ]
Checking table sq_rb_ast_mdata_val ...
[ OK ]
Checking table sq_rb_ast_mdata_dflt_val ...
[ OK ]
Checking table sq_rb_ast_wflow ...
[ OK ]
Checking table sq_rb_trig ...
[ OK ]
Checking table sq_rb_ast_role ...
[ OK ]
Checking table sq_rb_ctx_def ...
[ OK ]
Checking table sq_rb_saml_lnk ...
[ OK ]
Checking table sq_rb_cal_date_val ...
[ OK ]

system_integrity_fix_public_files.php

The system_integrity_fix_public_files.php script is used to evaluate and fix the files on the public data directory, updating any out-of-date files, creating any missing files, and removing any files that are private or should not be in the directory.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • The root ID of the asset under which to evaluate and repair.

system_integrity_fix_rollback_gaps.php

The system_integrity_fix_rollback_gaps.php script is used to identify time gaps in rollback tables and fix them if required.

The script is located in the /scripts directory of your Matrix system and takes the following parameters:

-s <system_root>

The root directory of your system.

--show-details

Specifies to show any found rollback record gaps.

--fix=<table_name>

Fixes the rollback gaps in the specified table. Use all to fix gaps in all tables (optional).

Example
$ php scripts/system_integrity_fix_rollback_gaps.php -s <SYSTEM_ROOT> --show-details --fix=all
IMPORTANT: You have selected the option to fix gaps in rollback entries for ALL Rollback tables.
This will remove all time gaps in the specified rollback tables.
Backing up db is recommended before running this script.
Are you sure you want to proceed (Y/n)? Y
Checking table sq_rb_ast ...
[ OK ]Checking table sq_rb_ast_lnk ...
[ OK ]Checking table sq_rb_shdw_ast_lnk ...
[ OK ]Checking table sq_rb_ast_lnk_tree ...
3 gaps found.
------------------------------------
0 => array (    "treeid" => "0006",    "gap_starts" => "2014-02-13 11:00:08",    "gap_ends" => "2014-03-10 14:07:17" ),
1 => array (    "treeid" => "000600000000",    "gap_starts" => "2014-02-13 11:00:08",    "gap_ends" => "2014-03-10 14:10:30" ),
2 => array (    "treeid" => "0006000000000001",    "gap_starts" => "2014-02-13 11:00:08",    "gap_ends" => "2014-04-17 16:22:11" )------------------------------------
[ NOT OK ]Fixing the rollback table sq_rb_ast_lnk_tree.
3 gaps removed.
[ FIXED ]Checking table sq_rb_ast_attr_val ...
[ OK ]Checking table sq_rb_ast_attr_uniq_val ...
[ OK ]Checking table sq_rb_ast_url ...
[ OK ]Checking table sq_rb_ast_path ...
[ OK ]Checking table sq_rb_ast_lookup ...
[ OK ]Checking table sq_rb_ast_lookup_value ...
[ OK ]Checking table sq_rb_ast_lookup_remap ...
[ OK ]Checking table sq_rb_ast_perm ...
[ OK ]Checking table sq_rb_ast_edit_access ...
[ OK ]Checking table sq_rb_ast_mdata ...
[ OK ]Checking table sq_rb_ast_mdata_val ...
[ OK ]Checking table sq_rb_ast_mdata_dflt_val ...
[ OK ]Checking table sq_rb_ast_wflow ...
[ OK ]Checking table sq_rb_trig ...
[ OK ]Checking table sq_rb_ast_role ...
[ OK ]Checking table sq_rb_ctx_def ...
[ OK ]Checking table sq_rb_saml_lnk ...
[ OK ]Checking table sq_rb_cal_date_val ...
[ OK ]

system_integrity_fix_sort_orders.php

The system_integrity_fix_sort_orders.php script is used to verify and correct the asset sort order in the database.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • The ID of the asset from which to start the repair.

An incorrect sort order can cause asset tree errors, especially in paginated lists. This script is quite intensive and can potentially run for an extended period. It is recommended that these factors be considered before running this script on a Live system.

system_integrity_foreign_keys.php

The system_integrity_foreign_keys.php script reports on the integrity of foreign keys within a Matrix database. This script defines relations between specific key fields (for instance, the asset ID field in the sq_ast table) and fields in other tables. If it finds a field in any table with the same name as one defined as related, it will report any values in that table that do not exist in the key table.

This script does not attempt to fix the integrity of the database. Instead, it reports on potentially invalid foreign keys and the number of invalid rows. The user could then use this information to write an SQL query to remove the invalid rows if desired.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

Example
$ php system_integrity_foreign_keys.php [system_root]

> checking table sq_ast...
sq_ast.assetid                   0 found
sq_ast.created_userid            0 found
sq_ast.updated_userid            0 found
sq_ast.published_userid          0 found
sq_ast.status_changed_userid     0 found
sq_ast_typ.type_code             0 found

> checking table sq_ast_attr...
sq_ast_attr.attrid               0 found
sq_ast_typ.type_code             0 found

...

system_integrity_form_submissions.php

The system_integrity_form_submissions.php script ensures that form submissions only appear under their associated form assets.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

Example
$ php system_integrity_form_submissions.php [system_root]

The following invalid Form Submissions will be deleted if you run this script with delete option:
Processing the form submission 1...
Processing the form submission 2...
Processing the form submission 3...
Processing the form submission 4...
Processing the form submission 5...
Processing the form submission 6...

There are 0 invalid form submission assets in the total of 6.

system_integrity_incomplete_attachments.php

The system_integrity_incomplete_attachments.php script will check for and delete any temporary incomplete attachments that were not automatically removed from the Matrix file system. There are two modes to this script: check and fix, determined by the --check and --fix parameters. Running this script in check mode will display affected form asset IDs, while running this script in fix mode will remove the associated incomplete attachments. The list of incomplete attachments found and deleted is also displayed at the end of this script.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • Either --check or --fix.

Example
$ php system_integrity_incomplete_attachments.php [system_root] --check

$ php system_integrity_incomplete_attachments.php [system_root] --fix

system_integrity_inconsistent_workflow_status.php

The system_integrity_inconsistent_workflow_status.php script will detect and fix assets with a status inconsistent with their current workflow statuses.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

--system=<SYSTEM_ROOT>

Where <SYSTEM_ROOT> is the root directory of your Matrix system.

--email=<EMAIL_ADDRESS>

This optional parameter allows you to specify an email address to send the report generated by this script.

--fix

This optional parameter allows you to fix any inconsistencies detected by this script.

Example
$ php scripts/system_integrity_inconsistent_workflow_status.php --system=[system_root].

Following assets are found to be in running workflow state but not in workflow status
#154 has status 16

The system_integrity_internal_links.php script ensures all links to assets in the system in bodycopy contents are using the internal format of (./?a=xxx). For example, you may have \www.example.com/?a=xxx. This script will convert this URL to ./?a=xxx. It locks each asset as it updates it and displays a Failed message for any asset that fails.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • The asset ID to check links under (optional).

Example
$ php system_integrity_internal_links.php [system_root]
WARNING: You are running this integrity checker on the whole system.
This is fine but:
  it may take a long time; and
  it will acquire locks on many of your assets (meaning you wont be able to
   edit content for a while)

WYSIWYG #26          [ OK ]
WYSIWYG #30          [ OK ]

The system_integrity_invalid_links.php script removes any significant links for all assets in the system where one or both sides of the link do not exist (invalid links).

This script will also report on any orphaned assets in the system and may recommend running the system_integrity_orphaned_assets.php script upon completion.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • Either -check or -delete.

Example
$php system_integrity_invalid_links.php [system_root] -delete
Found 1 invalid links
This script is about to be run SYSTEM WIDE in DELETE mode.
Are you sure you want to continue (y/n): y
Deleted Link ID: 14848 with Major ID: 3091 and Minor ID: 8976
There are 13 orphan assets found.
You must run system_integrity_orphaned_assets.php on the root folder to rescue these assets.

system_integrity_invalid_remaps.php

The system_integrity_invalid_remaps.php script cleans any invalid remaps, including useless remaps that lead to non-existent pages and infinite redirect loops.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

--system=<SYSTEM_ROOT>

Where <SYSTEM_ROOT> is the root directory of your Matrix system.

[--expired_remaps]

Identify remaps that have expired (optional).

[--invalid_old_url]

Identify remaps that have old, invalid URLs that match to existing assets (optional).

[--invalid_new_url]

Identify remaps with invalid new, invalid URLs, for example, redirecting to an non-existent asset URL (optional).

[--redirect_chain]

Identify redirect chains, shortening remaps if execute is specified (optional).

[--execute]

Clean the invalid remaps found in the above reports (optional).

Example
$ php scripts/system_integrity_invalid_remaps.php --system=<SYSTEM_ROOT> [--invalid_new_url]


## Invalid New URL ##
1 remaps deleted

system_integrity_orphaned_assets.php

The system_integrity_orphaned_assets.php script finds and links orphaned assets (i.e. ones with no links to them) underneath a specified asset ID, which should preferably be a folder.

This script is for troubleshooting purposes and should only be run if you are experiencing problems with your system.

This script is located in the /scripts directory of your Matrix system and takes the following parameter:

  • The system root directory.

  • The asset ID of the asset to which orphaned assets will be mapped.

Example
$ php system_integrity_orphaned_assets.php [system_root] 100
Enter the root password for "The System": ******
[ #1 ] Root Folder                                                     [ -- ]
[ #35 ] Tag Manager                                                    [ -- ]
[ #36 ] Manage Pending Accounts Scheduled Job                          [ -- ]
[ #2 ] System Management                                               [ -- ]

[ #16 ] Scheduled Jobs Manager                                         [ -- ]
[ #68 ] Orphaned Asset                                                 [ OK ]

Below is an explanation for the output you may see from system_integrity_orphaned_assets.php:

  • Indicates that the specified asset is not an orphan

    [ # 50 ] Example Folder              [ -- ]
  • Indicates that the asset is an orphan and has been moved underneath the asset specified in the second argument passed to the script.

    [ # 50 ] Example Folder              [ OK ]
  • Indicates that the asset is an orphan but was not able to be linked.

    [ # 50 ] Example Folder              [ FAILED ]

system_integrity_recover_file_versions.php

The system_integrity_recover_file_versions.php script will recover incorrect file versioning entries in Matrix.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • The running mode (test or recover).

  • The asset ID of the root node for which to perform the recovery.

  • The test running mode summarises any conflicts between file versions stored in the file system and the database.

You should back up your system before using this script.

system_integrity_run_tidy.php

The system_integrity_run_tidy.php script runs HTML tidy across all WYSIWYG editor cells in a system or under a particular asset. Please note that this script requires HTML tidy to be enabled and configured.

This script is located in the /scripts directory of your Matrix system and takes the following parameters:

  • The system root directory.

  • The asset ID under which to run HTML tidy.

Example
$ php system_integrity_content_links.php [system_root]
WARNING: You are running this checker on the whole system.
This is fine but:
 it may take a long time; and
 it will acquire locks on many of your assets (meaning you wont be able to edit
  content for a while

        WYSIWYG (#714)                            [TIDY PASS ]
        Content DIV (#713)                        [CONTENT PASS ]
        Page Contents (#712)                      [CONTENT PASS ]
        Library (#709)                            [CONTENT PASS ]

© 2015- Squiz Pty Ltd