27 error_reporting(E_ALL);
28 if ((php_sapi_name() !=
'cli')) {
29 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
32 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
33 if (empty($SYSTEM_ROOT)) {
34 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
38 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
39 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
43 $DELETING_ASSET_TYPE = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'';
44 if (empty($DELETING_ASSET_TYPE)) {
45 echo
"ERROR: You need to supply an asset type code as the second argument\n";
49 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
50 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
54 echo
'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.
'": ';
56 $root_password = rtrim(fgets(STDIN, 4094));
60 $root_user =& $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
61 if (!$root_user->comparePassword($root_password)) {
62 echo
"ERROR: The root password entered was incorrect\n";
67 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
68 echo
"ERROR: Failed login in as root user\n";
73 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
74 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
76 $sql =
'SELECT assetid FROM sq_ast WHERE type_code = :type_code';
81 if (!empty($assets_of_type)) {
84 foreach($assets_of_type as $index => $asset_id) {
87 $asset_ids_set =
'('.implode(
', ', $assets_of_type).
')';
89 $sql =
'SELECT linkid FROM sq_ast_lnk WHERE minorid in '.$asset_ids_set.
' OR majorid in '.$asset_ids_set;
99 $links_array = Array();
100 foreach ($res as $value) {
101 $GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($value[
'linkid']);
104 $links_set =
'('.implode(
', ', $links_array).
')';
106 $sql =
'DELETE FROM sq_ast_lnk WHERE linkid in '.$links_set;
112 $sql =
'DELETE FROM sq_ast_attr_val WHERE assetid in '.$asset_ids_set;
116 $sql =
'DELETE FROM sq_ast WHERE type_code = :type_code';
121 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
122 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();