18 require_once SQ_INCLUDE_PATH.
'/asset_management.inc';
46 'type' =>
'option_list',
51 'type' =>
'serialise',
63 'parameters' => Array(
64 'allow_empty' =>
false,
66 'description' =>
'DEPRECATED AS OF v0.3',
83 $res = parent::_upgrade($current_version);
85 if (version_compare($current_version,
'0.6',
'<')) {
86 echo(
'UPGRADING FORM QUESTION TYPE TICKBOX LIST FROM '.$current_version.
"\n");
94 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
95 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
97 pre_echo(
'Updating Tickbox List Question Types...');
100 $form_ids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form', FALSE, TRUE);
101 $question_assets = Array();
102 foreach ($form_ids as $form_id => $type) {
103 $form = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($form_id, $type[
'type_code']);
104 $question_assets += $form->getChildren($form->id,
'form_question_type_tickbox_list', TRUE);
106 $section_ids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form_section', FALSE, TRUE);
107 foreach ($section_ids as $section_id => $type) {
108 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_id, $type[
'type_code']);
109 $question_assets += $section->getChildren($section->id,
'form_question_type_tickbox_list', TRUE);
113 foreach ($question_assets as $id => $type) {
114 $q = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($id);
115 $options = $q->attr(
'options');
119 $orig_error_reporting = error_reporting();
120 error_reporting($orig_error_reporting ^ E_NOTICE);
121 $options_array_format = is_array(unserialize($options));
122 error_reporting($orig_error_reporting);
124 if (!$options_array_format) {
125 $options = str_replace(
"\r",
'', $options);
126 $opts = explode(
"\n", $options);
127 $q->setAttrValue(
'options', serialize($opts));
130 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
132 if (!$q->saveAttributes()) {
133 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
134 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
136 pre_echo(
'UPGRADE FAILED - Could not save attributes');
142 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
144 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($q);
149 pre_echo(
'Updated Tickbox List Question Types - '.$count.
' question(s)...');
151 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
152 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
154 pre_echo(
'TICKBOX LIST QUESTION TYPES SUCCESSFULLY UPGRADED TO VERSION 0.5');