39 return 'Invalid Incomplete Attachments Test';
52 return 'A test to find incomplete attachments under a form';
66 public static function test(&$messages, &$errors)
71 $form_assetids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetIds(
'form', FALSE);
72 foreach ($form_assetids as $assetid) {
73 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
74 $complete_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($assetid, SQ_LINK_TYPE_2,
'folder', TRUE,
'submissions_folder');
75 $path = $asset->data_path;
76 $path .=
'/incomplete_attachments';
77 $files = list_dirs($path);
78 foreach ($files as $file) {
79 if ((strpos($file,
's') === 0) && (assert_valid_assetid(substr($file, 1),
'', TRUE, FALSE))) {
81 $incomplete_submission_assetid = substr($file, 1);
82 $incomplete_submission = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($incomplete_submission_assetid,
'', TRUE);
83 if (is_null($incomplete_submission)) {
86 $errors[] =
'Form #'.$assetid.
' has an incomplete attachment directory for a non-existent submission (#'.$incomplete_submission_assetid.
')';
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)){
92 $errors[] =
'Form #'.$assetid.
' has an incomplete attachment directory for a complete submission (#'.$incomplete_submission_assetid.
')';
94 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($incomplete_submission, TRUE);
96 unset($incomplete_submission);
99 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
104 if (!empty($count)) $messages[] =
'There are '.$count.
' incomplete attachment directories for non-existent submissions found on the system';
105 if (!empty($count_2)) $messages[] =
'There are '.$count_2.
' incomplete attachment directories for complete submissions found on the system';