18 require_once SQ_INCLUDE_PATH.
'/asset_management.inc';
48 'attributes' => Array(
50 'type' =>
'serialise',
52 'description' =>
'array with keys "answers", "summary", "extra_data"',
58 'description' =>
'TRUE if submission complete, FALSE if incomplete and not yet submitted.',
63 'default' =>
'---------- --:--:--',
64 'parameters' => Array(
66 'show' => Array(
'd',
'm',
'y',
'h',
'i'),
68 'description' =>
'The date the form submission was submitted to Matrix',
70 'captcha_status' => Array(
74 'description' =>
'TRUE if a CAPTCHA has been correctly submitted for this form so far.',
81 'current_page' => Array(
85 'description' =>
'The page the user last saw on this submission, updated with the current page when a user jumps back and forth through the form',
88 'latest_page' => Array(
92 'description' =>
'The last page the user saw - ie. the page furthest along the line that has been seen, irrespective of whether a user backtracked to a previous page',
111 $res = parent::_upgrade($current_version);
113 if (version_compare($current_version,
'0.8',
'<')) {
114 echo(
'UPGRADING FORM SUBMISSION FROM '.$current_version.
"\n");
125 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
126 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
128 pre_echo(
'Updating Form Submissions...');
131 $submission_ids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form_submission', FALSE, TRUE);
134 foreach ($submission_ids as $id => $type) {
135 $submission = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($id);
136 $complete = $submission->attr(
'complete');
137 $submitted = $submission->attr(
'submitted');
140 $date = $submission->created;
143 if ($complete && $submitted ==
'---------- --:--:--') {
145 $answers = $submission->attr(
'attributes');
146 if (!isset($answers[
'answers'])) {
152 $section_assetids = Array();
153 foreach ($answers[
'answers'] as $assetid => &$data) {
154 $assetid_bits = explode(
':', $assetid, 2);
155 $real_assetid = $assetid_bits[0];
158 if (array_search($real_assetid, $section_assetids) === FALSE) {
159 $section_assetids[] = $real_assetid;
162 $real_asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($real_assetid),
'asset', FALSE,
'name');
163 if (empty($real_asset_info) === FALSE) {
164 $form_id = key($GLOBALS[
'SQ_SYSTEM']->am->getParents($real_assetid,
'form', FALSE));
173 if (!empty($form_id)) {
174 $form = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($form_id,
'');
175 $sub_folder = $form->getSubmissionsFolder(
'submissions_folder');
179 $sql =
'SELECT updated FROM sq_ast_lnk WHERE link_type=:type AND minorid=:minorid AND majorid=:majorid';
186 }
catch (Exception $e) {
187 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
188 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
190 pre_echo(
'UPGRADE FAILED - Database Error: '.$e->getMessage());
194 if (!empty($result)) {
195 $date = strtotime($result);
198 $_POST[
'SQ_FORM_'.$form->id.
'_SUBMISSION'] = $submission->id;
199 $submission->setAttrValue(
'xml', $form->getXML($date));
203 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
204 $submission->setAttrValue(
'submitted', ts_iso8601($date));
206 if (!$submission->saveAttributes()) {
207 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
208 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
210 pre_echo(
'UPGRADE FAILED - Could not save attributes');
213 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
216 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($submission, TRUE);
220 pre_echo(
'Updated - '.$count.
' form submission(s)...');
222 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
223 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
225 pre_echo(
'FORM SUBMISSIONS SUCCESSFULLY UPGRADED TO VERSION 0.8');