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';
41 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
44 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
45 echo
"ERROR: Failed login in as root user\n";
49 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
50 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
52 $old_date = date(
'Y-m-d', strtotime(
'-1 week'));
53 $sql =
"SELECT assetid
57 (select attrid from sq_ast_attr where (type_code = 'cron_job' or owning_type_code = 'cron_job') and name='when')
58 AND CAST(custom_val AS varchar2(255)) < :old_date";
62 if (empty($assetids)) {
63 echo
"No old cron jobs found\n";
65 echo
'Found '.count($assetids).
' old crons'.
"\n";
66 $assetids_list =
'('.implode(
', ', $assetids).
')';
69 $res =
MatrixDAL::executeSql(
'DELETE FROM sq_ast_lnk_tree WHERE linkid NOT IN (SELECT linkid FROM sq_ast_lnk)');
72 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
73 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();