Skip to content

Commit

Permalink
Merge branch 'hotfix/v0.20.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltata committed May 2, 2023
2 parents ad40d8f + a8604e5 commit e307658
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion application/Controller/AdminAjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<strong>Sorry.</strong> Missing run unit.';
Expand Down Expand Up @@ -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('<strong>Success.</strong> 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();
Expand Down
2 changes: 1 addition & 1 deletion application/Controller/RunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion application/Model/Item/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 8 additions & 2 deletions application/Model/RunUnit/RunUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RunUnit extends Model {

public $unit_id = null;

public $icon = "fa-user";
public $icon = "fa-question";

protected $body = '';

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions application/Model/SurveyStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define('FORMR_VERSION', 'v0.20.5');
define('FORMR_VERSION', 'v0.20.6');

define('APPLICATION_ROOT', __DIR__ . '/');
define('INCLUDE_ROOT', APPLICATION_ROOT);
Expand Down
10 changes: 10 additions & 0 deletions templates/admin/run/units/missing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="alert alert-danger col-xs-10">
<p>
This Run Unit is orphaned and could cause problems in your run. You can safely delete it if you do not recognise it anymore.
</p>
<p>
<br />
<i class="fa fa-warning"></i> If you are not sure if this will lead to data loss, please contact
your formr administrators to confim.
</p>
</div>

0 comments on commit e307658

Please sign in to comment.