Skip to content

Commit

Permalink
move actions list to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Jul 3, 2022
1 parent d524d74 commit 0dd8558
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 82 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Activity Log

## 1.0.0 - 2022-07-03
### Changed
- Move actions list to database in preparation for Actions CRUD UI

## 1.0.0-beta.2 - 2022-06-22
### Fixed
- Fix issue with uninstall
Expand Down
1 change: 1 addition & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Plugin extends BasePlugin
{
public bool $hasCpSection = true;
public bool $hasCpSettings = true;
public string $schemaVersion = '1.0.1';

public function init()
{
Expand Down
2 changes: 1 addition & 1 deletion src/assets/compiled/activity-log.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/assets/compiled/activity-log.min.js

Large diffs are not rendered by default.

49 changes: 7 additions & 42 deletions src/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ new Vue({


this.options.listColumns.siteId = this.sites
this.options.listColumns.actionSegments = data.actions.map(action=>({
id:action.action,
text:action.label
}))

window.svgPath = data.svgPath
this.svgPath = data.svgPath

Expand Down Expand Up @@ -66,6 +71,7 @@ new Vue({
loaded: false,
loadingTable: true,
sites: [],
actions:[],
userId: null,
columns: ['url', 'userId', 'siteId', 'isCp', 'isAjax', 'ip', 'method', 'actionSegments', 'responseCode', 'execTime', 'createdAt'],
options: {
Expand Down Expand Up @@ -113,48 +119,7 @@ new Vue({
},
listColumns: {
siteId: [],
actionSegments: [
{
id: 'allActions',
text: 'All Actions'
},
{
id: '["users","login"]',
text: 'Login'
},
{
id: '["users","logout"]',
text: 'Logout'
},
{
id: '["users","impersonate"]',
text: 'Impersonate User'
},
{
id: '["elements","apply-draft"]',
text: 'Apply Draft'
},
{
id: '["elements","save"]',
text: 'Save Element'
},
{
id: '["users","save-user"]',
text: 'Save User'
},
{
id: '["assets","generate-transform"]',
text: 'Generate Transform'
},
{
id: '["plugins","save-plugin-settings"]',
text: 'Save Plugin Settings'
},
{
id: '["sections","save-section"]',
text: 'Save Section'
}
],
actionSegments: [],
method: [
{
id: 'GET',
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/ActivityLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use craft\elements\User;
use craft\records\Site;
use matfish\ActivityLog\ActivityLogAssetBundle;
use matfish\ActivityLog\records\ActivityLogAction;
use matfish\ActivityLog\services\VueTablesActivityLogRetriever;
use yii\web\Response;

Expand All @@ -14,8 +15,8 @@ public function actionInitialData(): Response
{
$res = [
'sites'=>Site::find()->select(['id','name'])->all(),
'svgPath'=>$this->getSvgPath()

'svgPath'=>$this->getSvgPath(),
'actions'=>ActivityLogAction::find()->all()
];

return $this->asJson($res);
Expand Down
44 changes: 27 additions & 17 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace matfish\ActivityLog\migrations;


use craft\db\Migration;
use matfish\ActivityLog\services\CreateActionsTable;

class Install extends Migration
{
Expand All @@ -11,33 +13,41 @@ public function safeUp()
if (!$this->db->tableExists('{{%activitylog}}')) {
$this->createTable('{{%activitylog}}', [
'id' => $this->primaryKey()->notNull(),
'url'=>$this->string()->notNull(),
'query'=>$this->longText()->null(),
'payload'=>$this->longText()->null(),
'userId'=>$this->integer()->null(),
'execTime'=>$this->float()->null(),
'ip'=>$this->string(20),
'userAgent'=>$this->string(),
'isAjax'=>$this->boolean(),
'method'=>$this->string(10),
'siteId'=>$this->integer(),
'isCp'=>$this->boolean(),
'isAction'=>$this->boolean(),
'actionSegments'=>$this->string()->null(),
'responseCode'=>$this->smallInteger(),
'createdAt'=>$this->timestamp()
'url' => $this->string()->notNull(),
'query' => $this->longText()->null(),
'payload' => $this->longText()->null(),
'userId' => $this->integer()->null(),
'execTime' => $this->float()->null(),
'ip' => $this->string(20),
'userAgent' => $this->string(),
'isAjax' => $this->boolean(),
'method' => $this->string(10),
'siteId' => $this->integer(),
'isCp' => $this->boolean(),
'isAction' => $this->boolean(),
'actionSegments' => $this->string()->null(),
'responseCode' => $this->smallInteger(),
'createdAt' => $this->timestamp()
]);

$this->createIndex('activityLogCreatedAt_idx','{{%activitylog}}','createdAt');
$this->createIndex('activityLogUserId_idx','{{%activitylog}}','userId');
$this->createIndex('activityLogCreatedAt_idx', '{{%activitylog}}', 'createdAt');
$this->createIndex('activityLogUserId_idx', '{{%activitylog}}', 'userId');

}
if (!$this->db->tableExists('{{%activitylog_actions}}')) {
(new CreateActionsTable())->execute($this);
}

}

public function safeDown()
{
if ($this->db->tableExists('{{%activitylog}}')) {
$this->dropTable('{{%activitylog}}');
}

if ($this->db->tableExists('{{%activitylog_actions}}')) {
$this->dropTable('{{%activitylog_actions}}');
}
}
}
38 changes: 38 additions & 0 deletions src/migrations/m220703_102139_add_actions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace matfish\ActivityLog\migrations;

use Craft;
use craft\db\Migration;
use matfish\ActivityLog\records\ActivityLogAction;
use matfish\ActivityLog\services\CreateActionsTable;

/**
* m220703_102139_add_actions_table migration.
*/
class m220703_102139_add_actions_table extends Migration
{
/**
* @inheritdoc
*/
public function safeUp(): bool
{
if (!$this->db->tableExists('{{%activitylog_actions}}')) {
(new CreateActionsTable())->execute($this);
}

return true;
}

/**
* @inheritdoc
*/
public function safeDown(): bool
{
if ($this->db->tableExists('{{%activitylog_actions}}')) {
$this->dropTable('{{%activitylog_actions}}');
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?php


namespace matfish\ActivityLog\migrations;
namespace matfish\ActivityLog\services;


use craft\db\Migration;
use matfish\ActivityLog\records\ActivityLogAction;

class m220702_144330_add_actions_table extends Migration
class CreateActionsTable
{
public function safeUp()
{
if (!$this->db->tableExists('{{%activitylog_actions}}')) {
$this->createTable('{{%activitylog_actions}}', [
'id' => $this->primaryKey()->notNull(),
'action' => $this->string()->notNull(),
'label' => $this->string()->notNull(),
'native' => $this->boolean()->notNull(),
'createdAt' => $this->timestamp()
public function execute(Migration $migration) {
$migration->createTable('{{%activitylog_actions}}', [
'id' => $migration->primaryKey()->notNull(),
'action' => $migration->string()->notNull(),
'label' => $migration->string()->notNull(),
'native' => $migration->boolean()->notNull(),
'createdAt' => $migration->timestamp()
]);

$actions = [
Expand Down Expand Up @@ -66,13 +64,5 @@ public function safeUp()
$r->native = true;
$r->save();
}
}
}

public function safeDown()
{
if ($this->db->tableExists('{{%activitylog_actions}}')) {
$this->dropTable('{{%activitylog_actions}}');
}
}
}

0 comments on commit 0dd8558

Please sign in to comment.