Skip to content
Snippets Groups Projects
Commit d4be4f6c authored by Rich Lott / Artful Robot's avatar Rich Lott / Artful Robot
Browse files

Fix on off broken status

parent 8fa37d7b
Branches master
No related tags found
No related merge requests found
......@@ -43,12 +43,23 @@ class CreateBundle extends \Civi\Api4\Generic\AbstractQueryAction {
if (empty($rec['error'])) {
// (I'm not clear when 'error' would be set?)
if ($rec['status'] !== 'off') {
if (($rec['status'] ?? 'off') !== 'off') {
// If it's not deliberately off, try to load it.
$inlay = \Civi\Inlay\Type::fromArray($rec);
$updates = [];
if ($inlay->getStatus() === 'broken') {
$rec['error'] = "Inlay (config) is BROKEN.";
}
if ($inlay->getStatus() !== $rec['status']) {
// Increase visibility of brokeness. It is the way to healing.
// Also, note when we have healed.
\Civi::log()->info("Inlay $rec[id] changed status to " . $inlay->getStatus());
\Civi\Api4\Inlay::update(FALSE)
->setUpdateBundle(FALSE) /* avoid infinite loop... */
->addWhere('id', '=', $inlay->getID())
->addValue('status', $inlay->getStatus())
->execute();
}
}
else {
$rec['error'] = "Inlay is OFF.";
......
<?php
namespace Civi\Api4\Action\Inlay;
use Civi\Api4\Generic\DAOUpdateAction;
use Civi\Api4\Generic\Result;
class Update extends DAOUpdateAction {
use WriteTrait;
/**
* @inheritDoc
*/
public function _run(Result $result) {
parent::_run($result);
$this->updateBundle($result);
}
}
......@@ -28,6 +28,7 @@ trait WriteTrait {
if (is_array($record['config'])) {
$record['config'] = json_encode($record['config']);
}
parent::formatWriteValues($record);
}
......
......@@ -30,6 +30,15 @@ class Inlay extends Generic\DAOEntity {
->setCheckPermissions($checkPermissions);
}
/**
* @param bool $checkPermissions
* @return DAOUpdateAction
*/
public static function update($checkPermissions = TRUE) {
return (new Action\Inlay\Update(static::class, __FUNCTION__))
->setCheckPermissions($checkPermissions);
}
/**
* @param bool $checkPermissions
* @return DAOCreateAction
......
......@@ -216,7 +216,7 @@ abstract class Type {
*/
public function loadFromArray(array $array): Type {
// Copy most fields for instanceData
$this->instanceData = array_intersect_key($array, array_flip(['id', 'name', 'public_id', 'class']));
$this->instanceData = array_intersect_key($array, array_flip(['id', 'name', 'public_id', 'class', 'status']));
// Config is special.
$this->setConfig($array['config']);
return $this;
......@@ -270,7 +270,7 @@ abstract class Type {
* Return the internal name
*/
public function getStatus() {
return $this->instanceData['status'] ?? NULL;
return $this->instanceData['status'] ?? 'off';
}
/**
......@@ -475,6 +475,11 @@ abstract class Type {
throw new \RuntimeException("Invalid configuration in Inlay $data[id] of type $data[type]. See logs.");
}
}
elseif (!in_array($this->getStatus(), ['on', 'off'])) {
// If it was broken, and is not broken any more, leave it OFF,
// for safety. We want an admin to turn it ON.
$this->instanceData['status'] = 'off';
}
return $errors;
}
......
......@@ -29,8 +29,8 @@
<tbody>
<tr ng-repeat="inlay in inlays" ng-if="inlay && inlay.class === inlayType.class" class="{{inlay.status}}" >
<td>
<a href ng-click="toggleStatus(inlay)" ng-if="inlay.status === 'on'" title="{{ts('This Inlay can be used. Click to turn OFF.')}}">{{ts('ON')}} </span>
<a href ng-click="toggleStatus(inlay)" ng-if="inlay.status === 'off'" title="{{ts('This Inlay will not do anything while it is off. Click to turn ON')}}">{{ts('OFF')}} </span>
<a href ng-click="toggleStatus(inlay)" ng-if="inlay.status === 'on'" title="{{ts('This Inlay can be used. Click to turn OFF.')}}">{{ts('ON')}} </a>
<a href ng-click="toggleStatus(inlay)" ng-if="inlay.status === 'off'" title="{{ts('This Inlay will not do anything while it is off. Click to turn ON')}}">{{ts('OFF')}} </a>
<span ng-if="inlay.status === 'broken'" title="{{ts('Something is misconfigured; this Inlay will not function. Try editing and checking the settings.')}}" >{{ts('Broken!')}} </span>
</td>
<td>{{inlay.name}}</td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment