From 00cd5bd437df670964be5526a620a8a13808bb26 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Thu, 11 Jun 2020 09:13:12 +1200 Subject: [PATCH] NEW: Show job data in descriptor edit form. --- README.md | 11 +++++++ src/DataObjects/QueuedJobDescriptor.php | 38 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/README.md b/README.md index 4f706312..0b8204e3 100644 --- a/README.md +++ b/README.md @@ -819,6 +819,17 @@ As a consequence, the work might end up being very fragmented and each chunk may Some projects do not mind this however, so this solution may still be quite suitable. +## Show job data + +In case you need an easy access to additonal job data via CMS for debug purposes enable the `show_job_data` option by including the configuration below. + +```yaml +Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor: + show_job_data: true +``` + +This will add Job data and Messages raw tabs to the job descriptor edit form. Displayed information is read only. + ## Contributing ### Translations diff --git a/src/DataObjects/QueuedJobDescriptor.php b/src/DataObjects/QueuedJobDescriptor.php index b5728c1f..16af124e 100644 --- a/src/DataObjects/QueuedJobDescriptor.php +++ b/src/DataObjects/QueuedJobDescriptor.php @@ -14,6 +14,7 @@ use SilverStripe\Forms\HeaderField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\NumericField; +use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\TextField; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBDatetime; @@ -132,6 +133,14 @@ class QueuedJobDescriptor extends DataObject */ private static $default_sort = 'Created DESC'; + /** + * Show job data and raw messages in the edit form + * + * @config + * @var bool + */ + private static $show_job_data = false; + public function requireDefaultRecords() { parent::requireDefaultRecords(); @@ -318,6 +327,21 @@ public function getJobTypeString() return isset($map[$this->JobType]) ? $map[$this->JobType] : '(Unknown)'; } + /** + * @return string|null + */ + public function getSavedJobDataPreview() + { + return $this->SavedJobData; + } + + /** + * @return string|null + */ + public function getMessagesRaw() + { + return $this->SavedJobMessages; + } /** * Return a map of numeric JobType values to localisable string representations. @@ -507,6 +531,20 @@ public function getCMSFields() $fields->addFieldToTab('Root.Messages', LiteralField::create('Messages', $this->getMessages())); } + if ($this->config()->get('show_job_data')) { + $fields->addFieldsToTab('Root.JobData', [ + $jobDataPreview = TextareaField::create('SavedJobDataPreview', 'Job Data'), + ]); + + $jobDataPreview->setReadonly(true); + + $fields->addFieldsToTab('Root.MessagesRaw', [ + $messagesRaw = TextareaField::create('MessagesRaw', 'Messages Raw'), + ]); + + $messagesRaw->setReadonly(true); + } + if (Permission::check('ADMIN')) { return $fields; }