From 0eb2ac139ffcd4f183a3ace024f84a723a7faefd Mon Sep 17 00:00:00 2001 From: Jash Date: Sat, 21 Nov 2026 23:21:43 +0530 Subject: [PATCH] fix: API monitor add and edit start or stop zmtrack like the web save refs #7185 --- tests/php/test_api_monitors_save_zmtrack.php | 91 +++++++++++++++++++ web/api/app/Controller/MonitorsController.php | 2 + 2 files changed, 93 insertions(+) create mode 100644 tests/php/test_api_monitors_save_zmtrack.php diff --git a/tests/php/test_api_monitors_save_zmtrack.php b/tests/php/test_api_monitors_save_zmtrack.php new file mode 100644 index 0000000000..41ba0ca713 --- /dev/null +++ b/tests/php/test_api_monitors_save_zmtrack.php @@ -0,0 +1,91 @@ +row = is_array($row) ? $row : array(); } + function canEdit() { return true; } + function commandFieldChangesNotAllowed($f) { return array(); } + function Type() { return "Ffmpeg"; } + function Controllable() { return false; } + function Capturing() { return "Always"; } + function Deleted() { return false; } + function zmcControl($c) { self::$calls[] = "zmc:$c"; } + function sendControlCommand($c) { self::$calls[] = "ctl:$c"; } + function zmtrackControl($c) { self::$calls[] = "zmtrack:$c"; } +}'); + +class FakeModel { + public $id = 7; + function exists($id = null) { return true; } + function create() {} + function find($t = 'first', $o = array()) { return array('Monitor' => array('Id' => 7)); } + function save($d = null) { return true; } + function validates() { return true; } +} +class FakeRequest { + public $data = array(); + public $m; + function __construct($m) { $this->m = $m; } + function is($t) { return in_array($this->m, (array)$t, true); } +} +class FakeController { + public $Monitor; public $request; public $out; + function set($a) { $this->out = $a; } + function requestCommandFields() { return array(); } + function pinRequestId($m, $id) {} +} +eval('class FakeCtl extends FakeController { '.$fix(extractMethod($source, 'edit')).' '.$fix(extractMethod($source, 'add')).' }'); + +foreach (array('edit', 'add') as $which) { + ZM\Monitor::$calls = array(); + $c = new FakeCtl(); + $c->Monitor = new FakeModel(); + $c->request = new FakeRequest('post'); + global $user; $user = null; + if ($which == 'edit') $c->edit(7); else $c->add(); + check("$which starts zmtrack.pl after zmc", in_array('zmtrack:start', ZM\Monitor::$calls, true), true); +} +exit($failures ? 1 : 0); diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index f427ca9506..43db415b20 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -206,6 +206,7 @@ class MonitorsController extends AppController { ))['Monitor']); if ($saved->Capturing() != 'None' and $saved->Type() != 'WebSite') { $saved->zmcControl('start'); + $saved->zmtrackControl('start'); } //return $this->flash(__('The monitor has been saved.'), array('action' => 'index')); $message = 'Saved'; @@ -277,6 +278,7 @@ class MonitorsController extends AppController { if ($saved->Controllable()) { $saved->sendControlCommand('start'); } + $saved->zmtrackControl('start'); } } else { $message = 'Error ' . print_r($this->Monitor->invalidFields(), true);