Skip to content

Commit

Permalink
remove queue item when schedule delete, fix attribute history (#656)
Browse files Browse the repository at this point in the history
* remove queue item when schedule delete, fix attribute history

* remove scheduler for language

* tests

* changelog [skip ci]
  • Loading branch information
nadar authored Aug 24, 2021
1 parent 7602bf1 commit 768584b
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE

## 4.1.0

+ [#656](https://github.com/luyadev/luya-module-admin/pull/656) Ensure queue items are removed when schedule item is deleted, improved filter of upcoming queue events, fix issue with scheduler log for multiple attributes on the same model.
+ [#654](https://github.com/luyadev/luya-module-admin/pull/654) Fix issue with ngrest detail view when json is not an array.
+ [#496](https://github.com/luyadev/luya-module-admin/issues/496) Added default color for link elements in NgRest CRUD table.

Expand Down
4 changes: 2 additions & 2 deletions src/apis/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public function actionQueueJob($jobId)
* @return ActiveDataProvider
* @since 2.0.0
*/
public function actionSchedulerLog($model, $pk)
public function actionSchedulerLog($model, $pk, $target)
{
return new ActiveDataProvider([
'query' => Scheduler::find()->where(['model_class' => $model, 'primary_key' => $pk]),
'query' => Scheduler::find()->where(['model_class' => $model, 'primary_key' => $pk, 'target_attribute_name' => $target]),
'sort'=> ['defaultOrder' => ['schedule_timestamp' => SORT_ASC]],
'pagination' => false,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/messages/cn/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/de/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
'ngrestlog_controller_description' => 'Einträge des Model Event Logs werden beim Erstellen, Aktualisieren und Löschen von Datensätzen in CRUD Views der Administration erzeugt.',
'logger_controller_description' => 'Einträge des Application Logs werden vom [Logger Model](https://luya.io/api/luya-admin-models-Logger) veranlasst.',
'config_controller_description' => 'Erstellen Sie einen Konfigurations-Key und weisen diesem einen Wert zu mittels [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Listet alle unerledigten Jobs in der Warteschlange auf. Informationen zum korrekten Einrichten finden Sie im [Queue Guide](https://luya.io/guide/app-queue).',
'queuelog_controller_description' => 'Listet alle Jobs in der Warteschlange auf. Informationen zum korrekten Einrichten finden Sie im [Queue Guide](https://luya.io/guide/app-queue).',
'ngrest_delete_all_button_label' => 'Alle Daten löschen',
'ngrest_delete_all_button_confirm_message' => 'Wollen Sie wirklich alle Daten löschen? Dies kann nicht widerrufen werden!',
'storageimage_controller_description' => 'Zeigt alle Bilder an, die über das [Storage System](https://luya.io/guide/app-storage) erstellt wurden. Jedes Bild ist verknüpft mit einer Datei.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/el/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/fa/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/it/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/nl/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/pl/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/th/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/tr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/ua/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
2 changes: 1 addition & 1 deletion src/messages/vi/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
'ngrestlog_controller_description' => 'Model Event Log entries are captured when creating, updating or deleting records in CRUD views of the admin.',
'logger_controller_description' => 'Application Log entries are triggered by [Logger Model](https://luya.io/api/luya-admin-models-Logger).',
'config_controller_description' => 'Create configuration keys and assign a value using [Config Model](https://luya.io/api/luya-admin-models-Config).',
'queuelog_controller_description' => 'Lists all unprocessed queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'queuelog_controller_description' => 'Lists all queue jobs, read [Queue Guide](https://luya.io/guide/app-queue) for a proper setup.',
'ngrest_delete_all_button_label' => 'Delete all data',
'ngrest_delete_all_button_confirm_message' => 'Are you sure to delete all data? This can not be undone!',
'storageimage_controller_description' => 'Displays all images created by the [Storage System](https://luya.io/guide/app-storage). Every image is associated with a file.',
Expand Down
20 changes: 16 additions & 4 deletions src/models/QueueLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Yii;
use luya\admin\ngrest\base\NgRestModel;
use yii\db\Expression;

/**
* Queue Log.
Expand Down Expand Up @@ -42,9 +43,9 @@ public static function ngRestApiEndpoint()
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'id' => Yii::t('app', 'Log ID'),
'queue_id' => Yii::t('app', 'Queue ID'),
'title' => Yii::t('app', 'Title'),
'title' => Yii::t('app', 'Queue Job Title'),
'push_timestamp' => Yii::t('app', 'Push Timestamp'),
'run_timestamp' => Yii::t('app', 'Run Timestamp'),
'end_timestamp' => Yii::t('app', 'End Timestamp'),
Expand Down Expand Up @@ -103,7 +104,18 @@ public function ngRestRelations()
],
];
}


/**
* {@inheritDoc}
*/
public function ngRestFilters()
{
return [
'Upcoming' => self::find()->where(['is', 'run_timestamp', new Expression('null')]),
'Processed' => self::find()->where(['is not', 'run_timestamp', new Expression('null')]),
];
}

/**
* Get Queue Log Errors
*
Expand All @@ -113,4 +125,4 @@ public function getLogErrors()
{
return $this->hasMany(QueueLogError::class, ['queue_log_id' => 'id']);
}
}
}
22 changes: 21 additions & 1 deletion src/models/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public static function tableName()
return '{{%admin_scheduler}}';
}

public function init()
{
parent::init();
$this->on(self::EVENT_AFTER_DELETE, function() {
$queueId = Config::find()->where(['name' => "queueScheduler.{$this->id}", 'is_system' => true])->select(['value'])->scalar();

if (!empty($queueId)) {
Yii::$app->adminqueue->remove($queueId);
}
});
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -127,6 +139,14 @@ public function pushQueue()
$delay = 0;
}

Yii::$app->adminqueue->delay($delay)->push(new ScheduleJob(['schedulerId' => $this->id]));
$queueId = Yii::$app->adminqueue->delay($delay)->push(new ScheduleJob(['schedulerId' => $this->id]));

// until there is a migration, store informations in config:
// see: https://github.com/luyadev/luya-module-admin/issues/655
$config = new Config();
$config->is_system = 1;
$config->name = "queueScheduler.{$this->id}";
$config->value = $queueId;
$config->save();
}
}
2 changes: 1 addition & 1 deletion src/resources/dist/main.js

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/resources/js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,26 +562,26 @@ zaa.directive('insertPasteListener', ['$rootScope', function ($rootScope) {
*
* ```js
* <button ng-click="modalState=!modalState">Toggle Modal</button>
* <modal is-modal-hidden="modalState" modal-title="I am the Title">
* <h1>Modal Container</h1>
* <p>Hello world!</p>
* </modal>
* ```
*
* If you want to hidden use ng-if with modals, you have to use ng-if inside the modal like:
*
* ```js
* <modal is-modal-hidden="modalState">
* <div ng-if="!modalState">
* <p>This is only linked when modalState is visible</p>
* </div>
* </modal>
* ```
*
* > Using the ng-if outside of the modal wont work as it does not trigger the modalState due to child scope creation each time
* > the ng-if is visible.
*
*/
* <modal is-modal-hidden="modalState" modal-title="I am the Title">
* <h1>Modal Container</h1>
* <p>Hello world!</p>
* </modal>
* ```
*
* If you want to hidden use ng-if with modals, you have to use ng-if inside the modal like:
*
* ```js
* <modal is-modal-hidden="modalState">
* <div ng-if="!modalState">
* <p>This is only linked when modalState is visible</p>
* </div>
* </modal>
* ```
*
* > Using the ng-if outside of the modal wont work as it does not trigger the modalState due to child scope creation each time
* > the ng-if is visible.
*
*/
zaa.directive("modal", ['$timeout', function ($timeout) {
return {
restrict: "E",
Expand Down
2 changes: 1 addition & 1 deletion src/resources/js/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ zaa.directive("luyaSchedule", function() {
};

$scope.getLogTable = function(callback) {
$http.get('admin/api-admin-common/scheduler-log?model='+$scope.modelClass+'&pk=' + $scope.primaryKeyValue).then(function(response) {
$http.get('admin/api-admin-common/scheduler-log?model='+$scope.modelClass+'&pk=' + $scope.primaryKeyValue + '&target=' + $scope.attributeName).then(function(response) {
$scope.logs.archived = [];
$scope.logs.upcoming = [];

Expand Down
2 changes: 2 additions & 0 deletions tests/admin/models/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use luya\Exception;
use admintests\AdminModelTestCase;
use luya\admin\models\Config;
use luya\admin\models\Scheduler;
use luya\admin\models\Tag;
use luya\testsuite\fixtures\ActiveRecordFixture;
Expand Down Expand Up @@ -70,6 +71,7 @@ public function testPushToQueue()
$this->createAdminQueueTable();
$this->createAdminQueueLogFixture();
$this->createAdminNgRestLogFixture();
new NgRestModelFixture(['modelClass' => Config::class]);
$model = $this->fixture->newModel;
$model->model_class = Tag::class;
$model->target_attribute_name = 'name';
Expand Down

0 comments on commit 768584b

Please sign in to comment.