2018-12-20 01:18:30 -02:00
|
|
|
<?php
|
2020-11-25 10:31:24 -06:00
|
|
|
/*
|
|
|
|
|
* ModuleModelObserver.php
|
2018-12-20 01:18:30 -02:00
|
|
|
*
|
|
|
|
|
* Displays +,-,U,. while running discovery and adding,deleting,updating, and doing nothing.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* @link http://librenms.org
|
2020-11-25 10:31:24 -06:00
|
|
|
* @copyright 2020 Tony Murray
|
2018-12-20 01:18:30 -02:00
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2020-11-25 10:31:24 -06:00
|
|
|
namespace App\Observers;
|
2018-12-20 01:18:30 -02:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model as Eloquent;
|
|
|
|
|
|
2018-12-20 19:50:12 -06:00
|
|
|
class ModuleModelObserver
|
2018-12-20 01:18:30 -02:00
|
|
|
{
|
2019-06-06 23:12:13 +02:00
|
|
|
/**
|
|
|
|
|
* Install observers to output +, -, U for models being created, deleted, and updated
|
|
|
|
|
*
|
2020-11-18 20:21:04 -06:00
|
|
|
* @param string|\Illuminate\Database\Eloquent\Model $model The model name including namespace
|
2019-06-06 23:12:13 +02:00
|
|
|
*/
|
|
|
|
|
public static function observe($model)
|
|
|
|
|
{
|
2020-11-18 20:21:04 -06:00
|
|
|
static $observed_models = []; // keep track of observed models so we don't duplicate output
|
|
|
|
|
$class = ltrim($model, '\\');
|
|
|
|
|
|
|
|
|
|
if (! in_array($class, $observed_models)) {
|
2020-11-25 10:31:24 -06:00
|
|
|
$model::observe(new static());
|
2020-11-18 20:21:04 -06:00
|
|
|
$observed_models[] = $class;
|
2019-06-06 23:12:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-20 01:18:30 -02:00
|
|
|
public function saving(Eloquent $model)
|
|
|
|
|
{
|
2020-09-21 14:54:51 +02:00
|
|
|
if (! $model->isDirty()) {
|
2018-12-20 01:18:30 -02:00
|
|
|
echo '.';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updated(Eloquent $model)
|
|
|
|
|
{
|
2020-09-21 15:59:34 +02:00
|
|
|
d_echo('Updated data:', 'U');
|
2018-12-20 01:18:30 -02:00
|
|
|
d_echo($model->getDirty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function created(Eloquent $model)
|
|
|
|
|
{
|
|
|
|
|
echo '+';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleted(Eloquent $model)
|
|
|
|
|
{
|
|
|
|
|
echo '-';
|
|
|
|
|
}
|
|
|
|
|
}
|