Merged in bugfix/DRT-166 (pull request #7427)

DRT-166 Create a method to generate the report using a queue job

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-07-17 16:34:01 +00:00
committed by Julio Cesar Laura Avendaño

View File

@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use Illuminate\Queue\Console\WorkCommand as BaseWorkCommand;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Worker;
class WorkCommand extends BaseWorkCommand
@@ -28,4 +29,53 @@ class WorkCommand extends BaseWorkCommand
parent::__construct($worker);
}
/**
* Listen for the queue events in order to update the console output.
*
* @return void
*/
public function listenForEvents(): void
{
$this->laravel['events']->listen(JobProcessing::class, function ($event) {
$this->loadAdditionalClassesAtRuntime();
});
parent::listenForEvents();
}
/**
* This call the 'classLoaderForCommands.json' file, is required by artisan for dynamically
* access to plugin classes.
*/
private function loadAdditionalClassesAtRuntime(): void
{
if (!defined('PATH_PLUGINS')) {
return;
}
$content = scandir(PATH_PLUGINS, SCANDIR_SORT_ASCENDING);
foreach ($content as $value) {
if (in_array($value, ['.', '..'])) {
continue;
}
$path = PATH_PLUGINS . $value;
if (!is_dir($path)) {
continue;
}
//this file is required by artisan for dynamically access to class
$classloader = $path . PATH_SEP . 'classLoaderForCommands.json';
if (!file_exists($classloader)) {
continue;
}
$object = json_decode(file_get_contents($classloader), false);
if (empty($object)) {
continue;
}
if (!property_exists($object, 'classes') && !is_array($object->classes)) {
continue;
}
foreach ($object->classes as $classpath) {
require_once $path . PATH_SEP . $classpath;
}
}
}
}