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',
84 $res = parent::_upgrade($current_version);
86 if (version_compare($current_version,
'0.5',
'<')) {
87 echo(
'UPGRADING FORM QUESTION TYPE OPTION LIST FROM '.$current_version.
"\n");
95 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
96 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
98 pre_echo(
'Updating Option List Question Types...');
101 $form_ids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form', FALSE, TRUE);
102 $question_assets = Array();
103 foreach ($form_ids as $form_id => $type) {
104 $form = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($form_id, $type[
'type_code']);
105 $question_assets += $form->getChildren($form->id,
'form_question_type_option_list', TRUE);
107 $section_ids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form_section', FALSE, TRUE);
108 foreach ($section_ids as $section_id => $type) {
109 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_id, $type[
'type_code']);
110 $question_assets += $section->getChildren($section->id,
'form_question_type_option_list', TRUE);
114 foreach ($question_assets as $id => $type) {
115 $q = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($id);
116 $options = $q->attr(
'options');
120 $orig_error_reporting = error_reporting();
121 error_reporting($orig_error_reporting ^ E_NOTICE);
122 $options_array_format = is_array(unserialize($options));
123 error_reporting($orig_error_reporting);
125 if (!$options_array_format) {
126 $options = str_replace(
"\r",
'', $options);
127 $opts = explode(
"\n", $options);
128 $q->setAttrValue(
'options', serialize($opts));
131 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
133 if (!$q->saveAttributes()) {
134 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
135 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
137 pre_echo(
'UPGRADE FAILED - Could not save attributes');
143 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
145 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($q);
150 pre_echo(
'Updated Option List Question Types - '.$count.
' question(s)...');
152 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
153 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
155 pre_echo(
'OPTION LIST QUESTION TYPES SUCCESSFULLY UPGRADED TO VERSION 0.4');