Skip to content

Commit ef4f093

Browse files
committed
admin logs
1 parent 524e026 commit ef4f093

File tree

18 files changed

+143
-10
lines changed

18 files changed

+143
-10
lines changed

app/base/abstracts/AdminManageModelsPage.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ abstract class AdminManageModelsPage extends AdminFormPage
2626
{
2727
protected $objectInstance = null;
2828

29+
protected $admin_action_log_data = null;
30+
2931
/**
3032
* {@inheriydocs}
3133
*
@@ -233,6 +235,19 @@ public function getFrontendModelButton(FrontendModel $object, $class = 'light',
233235
return (string) $button;
234236
}
235237

238+
public function setAdminActionLogData($admin_action_log_data)
239+
{
240+
$this->admin_action_log_data = $admin_action_log_data;
241+
242+
return $this;
243+
}
244+
245+
246+
public function getAdminActionLogData()
247+
{
248+
return $this->admin_action_log_data;
249+
}
250+
236251
/**
237252
* gets object to show class name for loading
238253
*

app/base/abstracts/Model.php

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ abstract class Model extends ContainerAwareObject implements \ArrayAccess, \Iter
3535
*/
3636
public $tablename;
3737

38-
/** @var boolean is first save flag */
38+
/**
39+
* @var boolean first save flag
40+
*/
3941
protected $is_first_save;
4042

43+
/**
44+
* @var array|null original model data
45+
*/
46+
private $original_data = null;
47+
4148
/**
4249
* {@inheritdocs}
4350
*
@@ -240,6 +247,8 @@ public function fill($id)
240247
$this->dbrow = $dbrow;
241248
}
242249

250+
$this->is_first_save = $this->isNew();
251+
243252
return $this;
244253
}
245254

@@ -288,9 +297,12 @@ public function reset()
288297
$dbrow = $this->getDb()->table($this->dbrow->getTable(), $this->dbrow->getOriginalId());
289298
if ($dbrow) {
290299
$this->dbrow = $dbrow;
300+
$this->original_data = $this->dbrow->getData();
291301
}
292302
}
293303

304+
$this->is_first_save = $this->isNew();
305+
294306
return $this;
295307
}
296308

@@ -305,6 +317,7 @@ public static function load(ContainerInterface $container, $id)
305317
{
306318
$dbrow = $container->get('db')->table(static::defaultTableName(), $id);
307319
$object = new static($container, $dbrow);
320+
$object->setOriginalData($dbrow->getData());
308321
$object->setIsFirstSave(false);
309322
return $object;
310323
}
@@ -320,6 +333,7 @@ public static function new(ContainerInterface $container, $initialdata = [])
320333
$dbrow = $container->get('db')->createRow(static::defaultTableName());
321334
$dbrow->setData($initialdata);
322335
$object = new static($container, $dbrow);
336+
$object->setOriginalData(null);
323337
$object->setIsFirstSave(true);
324338
return $object;
325339
}
@@ -336,6 +350,7 @@ public static function loadBy(ContainerInterface $container, $field, $value)
336350
{
337351
$dbrow = $container->get('db')->table(static::defaultTableName())->where($field, $value)->limit(1)->fetch();
338352
$object = new static($container, $dbrow);
353+
$object->setOriginalData($dbrow->getData());
339354
$object->setIsFirstSave(false);
340355
return $object;
341356
}
@@ -521,6 +536,8 @@ public function persist()
521536

522537
$this->setIsFirstSave(false);
523538

539+
$this->original_data = $this->dbrow->getData();
540+
524541
return $this;
525542
}
526543

@@ -588,22 +605,47 @@ public function postRemove()
588605
return $this;
589606
}
590607

591-
/**
592-
*
593-
* [isFirstSave description]
594-
* */
595608
public function setIsFirstSave($is_first_save)
596609
{
597610
$this->is_first_save = $is_first_save;
598611
return $this;
599612
}
600613

601-
/**
602-
*
603-
* [isFirstSave description]
604-
* */
605614
public function isFirstSave()
606615
{
607616
return ($this->is_first_save == true);
608617
}
618+
619+
620+
protected function setOriginalData($original_data)
621+
{
622+
$this->original_data = $original_data;
623+
return $this;
624+
}
625+
626+
protected function getOriginalData($key = null)
627+
{
628+
if ($key != null && array_key_exists($key, $this->original_data)) {
629+
return $this->original_data[$key];
630+
}
631+
632+
return $this->original_data;
633+
}
634+
635+
public function getChangedData()
636+
{
637+
if ($this->getOriginalData() == null) {
638+
return $this->getData();
639+
}
640+
641+
$changed = [];
642+
643+
foreach ($this->getData() as $key => $value) {
644+
if ($this->getOriginalData($key) != $value) {
645+
$changed[$key] = ['now' => $value, 'original' => $this->getOriginalData($key)];
646+
}
647+
}
648+
649+
return $changed;
650+
}
609651
}

app/site/controllers/Admin/Blocks.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
293293
$block->config = json_encode($values['config']->getData());
294294
}
295295

296+
$this->setAdminActionLogData($block->getChangedData());
297+
296298
$block->persist();
297299

298300
$existing_rewrites = array_map(
@@ -324,6 +326,9 @@ function ($el) {
324326
break;
325327
case 'delete':
326328
$block->delete();
329+
330+
$this->setAdminActionLogData('Deleted block '.$block->getId());
331+
327332
break;
328333
}
329334

app/site/controllers/Admin/Config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,17 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
214214
$configuration->value = $values['value'];
215215
$configuration->website_id = $values['website_id'];
216216
$configuration->locale = !empty($values['locale']) ? $values['locale'] : null;
217+
218+
$this->setAdminActionLogData($configuration->getChangedData());
219+
217220
$configuration->persist();
218221

219222
break;
220223
case 'delete':
221224
$configuration->delete();
225+
226+
$this->setAdminActionLogData('Deleted config '.$configuration->getId());
227+
222228
break;
223229
}
224230

app/site/controllers/Admin/Cron.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,15 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
250250
$task->schedule = $values['schedule'];
251251
$task->active = intval($values['active']);
252252

253+
$this->setAdminActionLogData($task->getChangedData());
254+
253255
$task->persist();
254256
break;
255257
case 'delete':
256258
$task->delete();
259+
260+
$this->setAdminActionLogData('Deleted cron task '.$task->getId());
261+
257262
break;
258263
}
259264

app/site/controllers/Admin/Languages.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,15 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
200200
$language->native = $values['native'];
201201
$language->family = $values['family'];
202202

203+
$this->setAdminActionLogData($language->getChangedData());
204+
203205
$language->persist();
204206
break;
205207
case 'delete':
206208
$language->delete();
209+
210+
$this->setAdminActionLogData('Deleted language '.$language->getId());
211+
207212
break;
208213
}
209214

app/site/controllers/Admin/Links.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,15 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
256256
$link->locale = $values['frontend']['locale'];
257257
$link->website_id = $values['frontend']['website_id'];
258258

259+
$this->setAdminActionLogData($link->getChangedData());
260+
259261
$link->persist();
260262
break;
261263
case 'delete':
262264
$link->delete();
265+
266+
$this->setAdminActionLogData('Deleted link '.$link->getId());
267+
263268
break;
264269
case 'term_deassoc':
265270
if ($values['term_id']) {

app/site/controllers/Admin/Logs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected function getTemplateData()
107107
$log = $this->getContainer()->call([AdminActionLog::class, 'load'], ['id' => $this->getRequest()->query->get('id')]);
108108
} else {
109109
$data = $this->getContainer()->call([AdminActionLog::class, 'paginate'], ['order' => ['created_at' => 'DESC']]);
110-
$header = ['id', 'action', 'method', 'request', 'created_at', 'updated_at'];
110+
$header = ['id', 'action', 'method', 'url', 'created_at', 'updated_at'];
111111
}
112112

113113
break;

app/site/controllers/Admin/Media.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
320320
}
321321
$media->lazyload = $values->lazyload;
322322

323+
$this->setAdminActionLogData($media->getChangedData());
324+
323325
$media->persist();
324326

325327
if ($values['page_id'] != null) {
@@ -343,6 +345,9 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
343345
break;
344346
case 'delete':
345347
$media->delete();
348+
349+
$this->setAdminActionLogData('Deleted meida '.$media->getId());
350+
346351
break;
347352
}
348353
if ($this->getRequest()->request->get('page_id') != null) {

app/site/controllers/Admin/News.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,15 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
182182
$news->website_id = $values['frontend']['website_id'];
183183
$news->date = $values['date'];
184184

185+
$this->setAdminActionLogData($news->getChangedData());
186+
185187
$news->persist();
186188
break;
187189
case 'delete':
188190
$news->delete();
191+
192+
$this->setAdminActionLogData('Deleted news '.$news->getId());
193+
189194
break;
190195
}
191196
return $this->doRedirect($this->getControllerUrl());

0 commit comments

Comments
 (0)