Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
purge_trash.php
1 <?php
32 error_reporting(E_ALL);
33 if (ini_get('memory_limit') != '-1') ini_set('memory_limit', '-1');
34 
35 if (php_sapi_name() != 'cli') {
36  trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
37 }
38 
39 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
40 if (empty($SYSTEM_ROOT)) {
41  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
42  exit();
43 }
44 
45 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
46  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
47  exit();
48 }
49 
50 require_once $SYSTEM_ROOT.'/core/include/init.inc';
51 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
52 
53 $root_user = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
54 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
55  echo "ERROR: Failed logging in as root user\n";
56  exit();
57 }
58 
59 $vars = Array();
60 
61 // if a second argument is supplied
62 $purge_rootnode = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : 0;
63 if (!empty($purge_rootnode)) {
64  // do some checking to make sure there is a link to the trash folder
65  $trash_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trash_folder');
66  $db = $GLOBALS['SQ_SYSTEM']->db;
67  $sql = 'select
68  linkid
69  from
70  sq_ast_lnk
71  where
72  minorid = :root_node
73  and
74  majorid = :trash_assetid';
75 
76  $query = MatrixDAL::preparePdoQuery($sql);
77  MatrixDAL::bindValueToPdo($query, 'root_node', $purge_rootnode);
78  MatrixDAL::bindValueToPdo($query, 'trash_assetid', $trash_folder->id);
79  $linkid = MatrixDAL::executePdoOne($query);
80 
81  if (!empty($linkid)) {
82  // purge trash hipo will know what to do
83  $vars['purge_root_linkid'] = $linkid;
84  }
85 }
86 
87 $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
88 $errors = $hh->freestyleHipo('hipo_job_purge_trash', $vars);
89 if (count($errors)) {
90  trigger_error(print_r($errors, TRUE), E_USER_WARNING);
91  exit(1);
92 } else {
93  echo "\npurge_trash.php: Completed.\n";
94 }
95 
96 ?>