28 error_reporting(E_ALL);
29 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
31 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
32 if (empty($SYSTEM_ROOT)) {
33 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
37 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
38 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
42 $ACTION = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'';
43 $ACTION = ltrim($ACTION,
'-');
44 if (empty($ACTION) || ($ACTION !=
'fix' && $ACTION !=
'check')) {
45 echo
"ERROR: No action specified\n";
51 if ($ACTION ==
'fix') {
55 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
56 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
63 $form_assetids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetIds(
'form', FALSE);
64 foreach ($form_assetids as $assetid) {
65 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
66 $complete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($assetid, SQ_LINK_TYPE_2,
'folder', TRUE,
'submissions_folder');
67 $path = $asset->data_path;
68 $path .=
'/incomplete_attachments';
69 $files = list_dirs($path);
70 foreach ($files as $file) {
71 if ((strpos($file,
's') === 0) && (assert_valid_assetid(substr($file, 1),
'', TRUE, FALSE))) {
73 $incomplete_submission_assetid = substr($file, 1);
74 $incomplete_submission = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($incomplete_submission_assetid,
'', TRUE);
75 if (is_null($incomplete_submission)) {
77 echo
'Form #'.$assetid.
' still has some incomplete attachment directories for non-existent Submission #'.$incomplete_submission_assetid.
'.';
82 delete_directory($path.
'/'.$file);
88 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($incomplete_submission_assetid,
'folder', TRUE, NULL, NULL, TRUE, 1, 1);
89 if (!empty($complete_link) && !empty($parents) && array_key_exists($complete_link[
'minorid'], $parents)){
90 echo
'Form #'.$assetid.
' still has some incomplete attachment directories for completed Submission #'.$incomplete_submission_assetid.
'.';
95 delete_directory($path.
'/'.$file);
101 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($incomplete_submission, TRUE);
103 unset($incomplete_submission);
106 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
110 echo
"Incomplete attachment directories for non-existent submissions found: ".$count.
"\n";
111 echo
"Incomplete attachment directories for non-existent submissions deleted: ".$count_rm.
"\n";
112 echo
"Incomplete attachment directories for completed submissions found: ".$count_2.
"\n";
113 echo
"Incomplete attachment directories for completed submissions deleted: ".$count_rm_2.
"\n";