Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_incomplete_attachments.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Invalid Incomplete Attachments Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to find incomplete attachments under a form';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69  $count = 0;
70  $count_2 = 0;
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))) {
80  // This is an incomplete submission, so check if the submission is still valid
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)) {
84  $status = FALSE;
85  $count++;
86  $errors[] = 'Form #'.$assetid.' has an incomplete attachment directory for a non-existent submission (#'.$incomplete_submission_assetid.')';
87  } else {
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  $status = FALSE;
91  $count_2++;
92  $errors[] = 'Form #'.$assetid.' has an incomplete attachment directory for a complete submission (#'.$incomplete_submission_assetid.')';
93  }
94  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($incomplete_submission, TRUE);
95  }//end if
96  unset($incomplete_submission);
97  }//end if
98  }//end foreach
99  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
100  unset($asset);
101  }//end foreach
102 
103  if (!$status) {
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';
106  }//end if
107 
108  return $status;
109 
110  }//end test()
111 
112 }//end class
113 ?>