From ab97b621e7e61958ce7be07e20fb51862ff2888d Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 2 May 2023 12:06:59 +0200 Subject: [PATCH 1/2] Display warning message for orphan run units --- application/Controller/AdminAjaxController.php | 18 +++++++++++++++++- application/Controller/RunController.php | 2 +- application/Model/Item/Random.php | 2 +- application/Model/RunUnit/RunUnit.php | 10 ++++++++-- application/Model/SurveyStudy.php | 1 + templates/admin/run/units/missing.php | 10 ++++++++++ 6 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 templates/admin/run/units/missing.php diff --git a/application/Controller/AdminAjaxController.php b/application/Controller/AdminAjaxController.php index e33a95d4..07f8e3cb 100644 --- a/application/Controller/AdminAjaxController.php +++ b/application/Controller/AdminAjaxController.php @@ -93,6 +93,11 @@ private function ajaxGetUnit() { $params['id'] = (int) $id; $unit = RunUnitFactory::make($run, $params); $content = $unit->displayForRun(); + } elseif($this->request->getParam('run_unit_id')) { + $unit = RunUnit::findByRunUnitId($this->request->getParam('run_unit_id'), ['ignore_missing' => true]); + $unit->type = 'missing'; + $dialog = Template::get($unit->getTemplatePath('missing')); + $content = $unit->displayForRun($dialog); } else { $this->response->setStatusCode(500, 'Bad Request'); $msg = 'Sorry. Missing run unit.'; @@ -269,10 +274,21 @@ private function ajaxRemoveRunUnitFromRun() { $dbh = $this->dbh; if (($run_unit_id = $this->request->getParam('run_unit_id'))) { - $unit = RunUnit::findByRunUnitId($run_unit_id, $this->request->getParams()); + + $params = $this->request->getParams(); + $params['ignore_missing'] = true; + $unit = RunUnit::findByRunUnitId($run_unit_id, $params); + if (!$unit) { formr_error(404, 'Not Found', 'Requested Run Unit was not found'); } + + if (!$unit->id) { + // Just delete orphan units. @TODO investigate why orphan units happen + $unit->removeFromRun($this->request->getParam('special')); + alert('Success. Unit with ID ' . $this->request->run_unit_id . ' was deleted.', 'alert-success'); + return $this->response->setContent($this->site->renderAlerts()); + } $sess_key = __METHOD__ . $unit->id; $results = $unit->getUnitSessionsCount(); diff --git a/application/Controller/RunController.php b/application/Controller/RunController.php index b78e532d..91b26ae2 100644 --- a/application/Controller/RunController.php +++ b/application/Controller/RunController.php @@ -207,7 +207,7 @@ private function getPrivateActionMethod($action) { private function filterAssets($assets) { $vars = array(); - if ($this->run->use_material_design === true || $this->request->str('tmd') === 'true') { + if ($this->run->use_material_design || $this->request->str('tmd') === 'true') { if (DEBUG) { $this->unregisterAssets('site:custom'); $this->registerAssets('bootstrap-material-design'); diff --git a/application/Model/Item/Random.php b/application/Model/Item/Random.php index 4665bc2c..743826a9 100644 --- a/application/Model/Item/Random.php +++ b/application/Model/Item/Random.php @@ -3,7 +3,7 @@ class Random_Item extends Number_Item { public $type = 'random'; - public $input_attributes = array('type' => 'hidden', 'step' => 1, 'min' => 0, 'max' => 10000000); + public $input_attributes = array('type' => 'hidden', 'step' => 1, 'min' => 0, 'max' => 1); public $mysql_field = 'INT UNSIGNED DEFAULT NULL'; public $no_user_input_required = true; diff --git a/application/Model/RunUnit/RunUnit.php b/application/Model/RunUnit/RunUnit.php index 07bd8b9f..5f3fbe91 100644 --- a/application/Model/RunUnit/RunUnit.php +++ b/application/Model/RunUnit/RunUnit.php @@ -62,7 +62,7 @@ class RunUnit extends Model { public $unit_id = null; - public $icon = "fa-user"; + public $icon = "fa-question"; protected $body = ''; @@ -227,7 +227,7 @@ public static function getDefaults($type) { return array_val($defaults, $type, array()); } - protected function getTemplatePath($tpl = null) { + public function getTemplatePath($tpl = null) { $tpl = $tpl ?? strtolower($this->type); if ($tpl === 'page') { $tpl = 'endpage'; @@ -440,6 +440,12 @@ public static function findByRunUnitId($id, $params = []) { $row = DB::getInstance()->findRow('survey_run_units', ['id' => $id]); if ($row) { $run = new Run(null, $row['run_id']); + if (!$row['unit_id'] && isset($params['ignore_missing'])) { + $row['run_unit_id'] = $id; + $row['id'] = null; + return new RunUnit($run, $row); + } + $params = array_merge($params, ['id' => $row['unit_id']]); return RunUnitFactory::make($run, $params); } diff --git a/application/Model/SurveyStudy.php b/application/Model/SurveyStudy.php index b2bd26db..002df2c3 100644 --- a/application/Model/SurveyStudy.php +++ b/application/Model/SurveyStudy.php @@ -291,6 +291,7 @@ protected function toArray() { 'google_file_id' => $this->google_file_id, 'unlinked' => $this->unlinked, 'hide_results' => $this->hide_results, + 'use_paging' => $this->use_paging, 'created' => $this->created, 'modified' => $this->modified, ]; diff --git a/templates/admin/run/units/missing.php b/templates/admin/run/units/missing.php new file mode 100644 index 00000000..b2ee3110 --- /dev/null +++ b/templates/admin/run/units/missing.php @@ -0,0 +1,10 @@ +
+

+ This Run Unit is orphaned and could cause problems in your run. You can safely delete it if you do not recognise it anymore. +

+

+
+ If you are not sure if this will lead to data loss, please contact + your formr administrators to confim. +

+
\ No newline at end of file From a8604e5eb039da31c452469a3a7429d76853893b Mon Sep 17 00:00:00 2001 From: Cyril Tata Date: Tue, 2 May 2023 12:07:20 +0200 Subject: [PATCH 2/2] version bump --- CHANGELOG.md | 5 +++++ setup.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5daa0fb..fce49c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [v0.20.6] - 02.05.2023 +### Fixed +* Display a warning message for orphaned run units and enable deletion. +* Other minor bug fixes + ## [v0.20.5] - 20.10.2022 ### Added * User search by email in admin diff --git a/setup.php b/setup.php index a6dac528..c50274dd 100644 --- a/setup.php +++ b/setup.php @@ -1,6 +1,6 @@