Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Dec 14, 2022
2 parents e05052f + 8e521f8 commit 971b1a7
Show file tree
Hide file tree
Showing 25 changed files with 504 additions and 345 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/main.yml
Expand Up @@ -13,11 +13,12 @@ on:

jobs:
CI-pipeline:
runs-on: ubuntu-18.04 # ubuntu runner hosted by Github
runs-on: ubuntu-20.04 # ubuntu runner hosted by Github
strategy:
matrix:
# Specify what versions of php you want to test
php-versions: ['7.2', '8.0']
#php-versions: ['7.2', '8.0']
php-versions: ['8.0']
# Env vars for this job
env:
DBENGINE: INNODB
Expand Down Expand Up @@ -57,7 +58,7 @@ jobs:
run: |
# Set up the Apache and PHP
sudo apt-get update > /dev/null
sudo apt install php libapache2-mod-php7.2 -y
sudo apt install php php-mysql php8.0-mysql php7.2-mysql libapache2-mod-php8.0 -y
sudo cp -f ./tests/CI-pipeline/github-actions-apache /etc/apache2/sites-available/000-default.conf
sudo sed -e "s?%CI_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf
Expand All @@ -84,21 +85,23 @@ jobs:
# https://discuss.gogs.io/t/solved-mysql-error-1064-while-running-first-install/1604
# InnoDB variables ARE already set to desired values in Github runner (ubuntu-18.04)
sudo systemctl start mysql
sudo service mysql status
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'root';" || true
mysql -uroot -proot -e "Show variables like '%large%';"
mysql -uroot -proot -e "Show variables like '%innodb_file%';"
mysql -uroot -proot -e "Show variables like '%innodb_default%';"
- name: Load custom console and start the Application
run: |
php application/commands/console.php install admin password TravisLS no@email.com verbose
cp application/config/config-sample-mysql.php application/config/config.php
php application/commands/console.php install admin password TravisLS no@email.com verbose
# Enable debug=2 in config file. OBS: This assumes debug is on line 61.
# TODO: Disable, a lines was added to config file and some tests started to fail.
# NB: EmCache is always disabled when debug => 2
# NB: There can be a difference in assets used when debug = 0 or 2 (minified version or not)
# sed -i '84s/.*/ "debug"=>2,/' application/config/config.php
# sed -i '60s/.*/ "debug"=>2,/' application/config/config.php
# cat application/config/config.php
- name: Run syntax check, CodeSniffer, MessDetector, ...
Expand All @@ -107,8 +110,18 @@ jobs:
- name: Test the server
run: |
# Test server.
wget localhost
cat index.html
wget -O - localhost
#sudo tail -n 500 /var/log/apache2/error.log || true
#sudo tail -n 500 /var/log/nginx/error.log || true
#sudo tail -n 500 /var/log/php7.4-fpm.log || true
#sudo tail -n 500 /var/log/php7.2-fpm.log || true
#sudo tail -n 500 /var/log/php8.0-fpm.log || true
# NOTE: php --version might not be the same as setup in apache. Use fwrite(STDERR, phpversion()); in index.php to be sure.
#which php
#php --version
#php -r 'phpinfo();' | grep log
#php --info | grep log
#find /var/log
# Chromedriver setup.
# Note: Keep getting timeout problems on Travis with chromedriver.
Expand Down
4 changes: 2 additions & 2 deletions application/config/version.php
Expand Up @@ -12,9 +12,9 @@
*/

$config['versionnumber'] = '5.5.0-dev';
$config['dbversionnumber'] = 494;
$config['dbversionnumber'] = 495;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['templateapiversion'] = 3;
$config['assetsversionnumber'] = '30309';
$config['assetsversionnumber'] = '30310';
return $config;
115 changes: 113 additions & 2 deletions application/helpers/admin/import_helper.php
Expand Up @@ -136,7 +136,8 @@ function XMLImportGroup($sFullFilePath, $iNewSID, $bTranslateLinksFields)
// We have to run the question table data two times - first to find all main questions
// then for subquestions (because we need to determine the new qids for the main questions first)


/** @var Question[] */
$importedQuestions = [];
$results['questions'] = 0;
if (isset($xml->questions)) {
foreach ($xml->questions->rows->row as $row) {
Expand Down Expand Up @@ -209,6 +210,7 @@ function XMLImportGroup($sFullFilePath, $iNewSID, $bTranslateLinksFields)
}
$aQIDReplacements[$iOldQID] = $oQuestion->qid;
$results['questions']++;
$importedQuestions[$aQIDReplacements[$iOldQID]] = $oQuestion;
}

if (isset($oQuestionL10n)) {
Expand Down Expand Up @@ -415,6 +417,8 @@ function XMLImportGroup($sFullFilePath, $iNewSID, $bTranslateLinksFields)
if (isset($xml->question_attributes)) {
$aAllAttributes = questionHelper::getAttributesDefinitions();

/** @var array<integer,array<string,mixed>> List of "answer order" related attributes, grouped by qid */
$answerOrderAttributes = [];
foreach ($xml->question_attributes->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
Expand All @@ -440,6 +444,18 @@ function XMLImportGroup($sFullFilePath, $iNewSID, $bTranslateLinksFields)
continue;
}

// Keep "answer order" related attributes in an array to process later (because we need to combine two attributes)
if (
$insertdata['attribute'] == 'alphasort'
|| (
$insertdata['attribute'] == 'random_order'
&& in_array($importedQuestions[$insertdata['qid']]->type, ['!', 'L', 'O', 'R'])
)
) {
$answerOrderAttributes[$insertdata['qid']][$insertdata['attribute']] = $insertdata['value'];
continue;
}

if (
$iDBVersion < 156 && isset($aAllAttributes[$insertdata['attribute']]['i18n']) &&
$aAllAttributes[$insertdata['attribute']]['i18n']
Expand All @@ -453,6 +469,29 @@ function XMLImportGroup($sFullFilePath, $iNewSID, $bTranslateLinksFields)
}
$results['question_attributes']++;
}

// Process "answer order" attributes
foreach ($answerOrderAttributes as $importedQid => $questionAttributes) {
if (!empty($questionAttributes['random_order'])) {
$insertdata = [
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'random',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
continue;
}
if (!empty($questionAttributes['alphasort'])) {
$insertdata = [
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'alphabetical',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
}
}
}


Expand Down Expand Up @@ -876,6 +915,8 @@ function XMLImportQuestion($sFullFilePath, $iNewSID, $iNewGID, $options = array(
// Import questionattributes --------------------------------------------------------------
if (isset($xml->question_attributes)) {
$aAllAttributes = questionHelper::getAttributesDefinitions();
/** @var array<string,mixed> List of "answer order" related attributes */
$answerOrderAttributes = [];
foreach ($xml->question_attributes->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
Expand All @@ -899,6 +940,18 @@ function XMLImportQuestion($sFullFilePath, $iNewSID, $iNewGID, $options = array(
continue;
}

// Keep "answer order" related attributes in an array to process later (because we need to combine two attributes)
if (
$insertdata['attribute'] == 'alphasort'
|| (
$insertdata['attribute'] == 'random_order'
&& in_array($oQuestion->type, ['!', 'L', 'O', 'R'])
)
) {
$answerOrderAttributes[$insertdata['attribute']] = $insertdata['value'];
continue;
}

if (
$iDBVersion < 156 &&
isset($aAllAttributes[$insertdata['attribute']]['i18n']) &&
Expand Down Expand Up @@ -926,6 +979,25 @@ function XMLImportQuestion($sFullFilePath, $iNewSID, $iNewGID, $options = array(
}
}

// Process "answer order" attributes
if (!empty($answerOrderAttributes['random_order'])) {
$insertdata = [
'qid' => $newqid,
'attribute' => 'answer_order',
'value' => 'random',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
} elseif (!empty($answerOrderAttributes['alphasort'])) {
$insertdata = [
'qid' => $newqid,
'attribute' => 'answer_order',
'value' => 'alphabetical',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
}

// Import defaultvalues ------------------------------------------------------
importDefaultValues($xml, $aLanguagesSupported, $aQIDReplacements, $results);

Expand Down Expand Up @@ -1441,6 +1513,8 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
// We have to run the question table data two times - first to find all main questions
// then for subquestions (because we need to determine the new qids for the main questions first)
$aQuestionsMapping = array(); // collect all old and new question codes for replacement
/** @var Question[] */
$importedQuestions = [];
if (isset($xml->questions)) {
// There could be surveys without a any questions.
foreach ($xml->questions->rows->row as $row) {
Expand Down Expand Up @@ -1520,8 +1594,8 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
throw new Exception(gT("Error while saving: ") . print_r($oQuestion->errors, true));
}
$aQIDReplacements[$iOldQID] = $oQuestion->qid;
;
$results['questions']++;
$importedQuestions[$aQIDReplacements[$iOldQID]] = $oQuestion;
}

if (isset($oQuestionL10n)) {
Expand Down Expand Up @@ -1747,6 +1821,8 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
// Import questionattributes -------------------------------------------------
if (isset($xml->question_attributes)) {
$aAllAttributes = questionHelper::getAttributesDefinitions();
/** @var array<integer,array<string,mixed>> List of "answer order" related attributes, grouped by qid */
$answerOrderAttributes = [];
foreach ($xml->question_attributes->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
Expand Down Expand Up @@ -1786,6 +1862,18 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
continue;
}

// Keep "answer order" related attributes in an array to process later (because we need to combine two attributes)
if (
$insertdata['attribute'] == 'alphasort'
|| (
$insertdata['attribute'] == 'random_order'
&& in_array($importedQuestions[$insertdata['qid']]->type, ['!', 'L', 'O', 'R'])
)
) {
$answerOrderAttributes[$insertdata['qid']][$insertdata['attribute']] = $insertdata['value'];
continue;
}

if ($iDBVersion < 156 && isset($aAllAttributes[$insertdata['attribute']]['i18n']) && $aAllAttributes[$insertdata['attribute']]['i18n']) {
foreach ($aLanguagesSupported as $sLanguage) {
$insertdata['language'] = $sLanguage;
Expand All @@ -1806,6 +1894,29 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = null, $sNewSurveyName = nul
checkWrongQuestionAttributes($insertdata['qid']);
$results['question_attributes']++;
}

// Process "answer order" attributes
foreach ($answerOrderAttributes as $importedQid => $questionAttributes) {
if (!empty($questionAttributes['random_order'])) {
$insertdata = [
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'random',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
continue;
}
if (!empty($questionAttributes['alphasort'])) {
$insertdata = [
'qid' => $importedQid,
'attribute' => 'answer_order',
'value' => 'alphabetical',
];
App()->db->createCommand()->insert('{{question_attributes}}', $insertdata);
$results['question_attributes']++;
}
}
}

// Import defaultvalues ------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -2203,7 +2203,7 @@ public function list_participants($sSessionKey, $iSurveyID, $iStart = 0, $iLimit
$value = $valueOrTuple[1];
$oCriteria->compare($columnName, $operator . $value);
}
} elseif (is_string($valueOrTuple)) {
} elseif (is_string($valueOrTuple) || is_null($valueOrTuple)) {
if (array_key_exists($columnName, $aConditionFields)) {
$aAttributeValues[$columnName] = $valueOrTuple;
}
Expand Down
36 changes: 35 additions & 1 deletion application/helpers/update/updates/Update_492.php
Expand Up @@ -6,6 +6,40 @@ class Update_492 extends DatabaseUpdateBase
{
public function up()
{
$this->db->createCommand()->addColumn('{{users}}', 'expires', 'datetime');
// Handle questions with random_order = 1
$this->db->createCommand(
"INSERT INTO {{question_attributes}} (qid, " . $this->db->quoteColumnName("attribute") . ", " . $this->db->quoteColumnName("value") . ")
SELECT
qa.qid,
'answer_order' AS " . $this->db->quoteColumnName("attribute") . ",
'random' AS " . $this->db->quoteColumnName("value") . "
FROM {{question_attributes}} qa
JOIN {{questions}} q ON qa.qid = q.qid
WHERE
" . $this->db->quoteColumnName("attribute") . " = 'random_order'
AND " . $this->db->quoteColumnName("value") . " = '1'
AND q.type IN ('!', 'L', 'O', 'R')"
)->execute();

// Handle questions with alphasort = 1 and random_order = 0
$this->db->createCommand(
"INSERT INTO {{question_attributes}} (qid, " . $this->db->quoteColumnName("attribute") . ", " . $this->db->quoteColumnName("value") . ")
SELECT
a.qid,
'answer_order' AS " . $this->db->quoteColumnName("attribute") . ",
'alphabetical' AS " . $this->db->quoteColumnName("value") . "
FROM (
SELECT *
FROM {{question_attributes}}
WHERE " . $this->db->quoteColumnName("attribute") . " = 'alphasort'
AND " . $this->db->quoteColumnName("value") . " = '1'
) a LEFT JOIN (
SELECT
qid,
" . $this->db->quoteColumnName("value") . " AS random_order
FROM {{question_attributes}}
WHERE " . $this->db->quoteColumnName("attribute") . " = 'random_order'
) r ON a.qid = r.qid WHERE random_order = '0' OR random_order IS NULL"
)->execute();
}
}

0 comments on commit 971b1a7

Please sign in to comment.