18 require_once SQ_INCLUDE_PATH.
'/asset_management.inc';
20 define(
'SQ_DELIMITER_UNIX',
"\n");
21 define(
'SQ_DELIMITER_WINDOWS',
"\r\n");
22 define(
'SQ_DELIMITER_MAC',
"\n");
54 'type' =>
'serialise',
61 'parameters' => Array(
62 'allow_empty' => FALSE,
72 'type' =>
'serialise',
75 'allow_empty' => Array(
79 'parameters' => Array(
80 'allow_empty' => FALSE,
88 'empty_text' => Array(
91 'default' =>
'-- Leave Empty --',
108 if (!parent::_upgrade($current_version))
return FALSE;
110 $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(),
'name'));
112 if (version_compare($current_version,
'0.5',
'<')) {
113 pre_echo(
'STARTING UPGRADE OF '.$asset_name.
' FROM VERSION '.$current_version.
' TO VERSION 0.5');
117 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
118 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
120 pre_echo(
'Updating Select Question Types...');
123 $form_email = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form_email', FALSE, TRUE);
124 $form_email += $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'form_section', FALSE, TRUE);
125 $form_email += $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'simple_form', FALSE, TRUE);
126 foreach ($form_email as $fe_id => $fe_blank) {
127 $fe = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($fe_id, $fe_blank[
'type_code']);
129 $q_value = $fe->attr(
'questions');
132 foreach ($q_value as $q_place_id => $q_id) {
133 if (isset($q_id[
'type_code'])) {
134 $type_code_index =
'type_code';
135 }
else if (isset($q_id[
'question_type_code'])) {
136 $type_code_index =
'question_type_code';
140 if ($q_id[$type_code_index] ==
'form_question_type_select') {
141 $options = $q_id[
'attributes'][
'options'];
144 $format_check = strpos($options,
"\r");
145 if ($format_check === FALSE) {
146 $opt = explode(SQ_DELIMITER_UNIX, $options);
148 $opt = explode(SQ_DELIMITER_WINDOWS, $options);
152 $processed_attribute = Array();
153 foreach ($opt as $ol) {
154 $processed_attribute[$ol] = $ol;
158 $processed_attribute = serialize($processed_attribute);
161 $q_value[$q_place_id][
'attributes'][
'options'] = $processed_attribute;
170 $fe->setAttrValue(
'questions', $q_value);
172 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
174 if (!$fe->saveAttributes()) {
175 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
176 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
178 pre_echo($asset_name.
' UPGRADE FAILED - Could not save attributes');
182 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
184 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($fe);
189 pre_echo(
'Updated Select Question Types - '.$count.
' question(s)...');
191 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
192 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
194 pre_echo($asset_name.
' SUCCESSFULLY UPGRADED TO VERSION 0.5');