Files
zoneminder/web/api/app/Model/State.php
T
nicandClaude Opus 5.5 ed8d648efa fix(api): key States by Id so view, edit and delete work (#5173)
The State model still declared primaryKey = 'Name' from before
zm_update-1.28.99 gave States an Id primary key. The REST routes only
match numeric ids, so states/<id>.json view/edit/delete looked up a
state *named* <id> and always failed, and names don't match the routes.
Through states/edit/<name>.json, edit never set the record id and
inserted a new nameless state instead of updating; view had no
_serialize and returned 500.

Use the default Id key. view serializes the state; edit sets the id,
accepts POST/PUT only and, like add, answers {message: Saved} or the
validation errors (as Monitors and Zones do) instead of an empty flash.
Names must be non-empty and unique, since zmpkg.pl and
states/change/<name> select states by name. index, change and delete
are unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 17:44:00 -04:00

43 lines
699 B
PHP

<?php
App::uses('AppModel', 'Model');
/**
* State Model
*
*/
class State extends AppModel {
/**
* Use table
*
* @var mixed False or table name
*/
public $useTable = 'States';
/**
* Display field
*
* @var string
*/
public $displayField = 'Name';
/**
* Validation rules. States are keyed by Id; Name is what zmpkg.pl and
* states/change/<name> use, so it must be set and unique.
*
* @var array
*/
public $validate = array(
'Name' => array(
'notBlank' => array(
'rule' => array('notBlank'),
'message' => 'A state needs a name',
),
'isUnique' => array(
'rule' => array('isUnique'),
'message' => 'A state with this name already exists',
),
),
);
}