PMCORE-1868 Error when derivate case with trigger which call a class from plugin
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Queue\Console\WorkCommand as BaseWorkCommand;
|
use Illuminate\Queue\Console\WorkCommand as BaseWorkCommand;
|
||||||
use Illuminate\Queue\Events\JobProcessing;
|
use Illuminate\Queue\Events\JobProcessing;
|
||||||
use Illuminate\Queue\Worker;
|
use Illuminate\Queue\Worker;
|
||||||
@@ -44,38 +45,64 @@ class WorkCommand extends BaseWorkCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This call the 'classLoaderForCommands.json' file, is required by artisan for dynamically
|
* This is required by artisan for dynamically access to plugin classes.
|
||||||
* access to plugin classes.
|
|
||||||
*/
|
*/
|
||||||
private function loadAdditionalClassesAtRuntime(): void
|
private function loadAdditionalClassesAtRuntime(): void
|
||||||
{
|
{
|
||||||
|
//load the main plugin classes because inside is the definition 'set_include_path()'
|
||||||
if (!defined('PATH_PLUGINS')) {
|
if (!defined('PATH_PLUGINS')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$content = scandir(PATH_PLUGINS, SCANDIR_SORT_ASCENDING);
|
$files = File::files(PATH_PLUGINS);
|
||||||
foreach ($content as $value) {
|
foreach ($files as $file) {
|
||||||
if (in_array($value, ['.', '..'])) {
|
$isPhpFile = strtolower(File::extension($file)) === "php";
|
||||||
|
if (!$isPhpFile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$path = PATH_PLUGINS . $value;
|
require_once $file;
|
||||||
if (!is_dir($path)) {
|
}
|
||||||
|
//load the classes of the plugins when is required dynamically.
|
||||||
|
$closure = function($className) {
|
||||||
|
if (class_exists($className)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!defined('PATH_PLUGINS')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$searchFiles = function($path) use(&$searchFiles, $className) {
|
||||||
|
$directories = File::directories($path);
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
$omittedDirectories = [
|
||||||
|
'bin', 'cache', 'colosa', 'config',
|
||||||
|
'data', 'documentation', 'fields',
|
||||||
|
'files', 'js', 'log', 'node_modules',
|
||||||
|
'public_html', 'resources', 'routes',
|
||||||
|
'templates', 'tests', 'translations',
|
||||||
|
'vendor', 'view', 'views'
|
||||||
|
];
|
||||||
|
if (in_array(File::basename($directory), $omittedDirectories)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//this file is required by artisan for dynamically access to class
|
$searchFiles($directory);
|
||||||
$classloader = $path . PATH_SEP . 'classLoaderForCommands.json';
|
$files = File::files($directory);
|
||||||
if (!file_exists($classloader)) {
|
foreach ($files as $file) {
|
||||||
|
$isPhpFile = strtolower(File::extension($file)) === "php";
|
||||||
|
if (!$isPhpFile) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$object = json_decode(file_get_contents($classloader), false);
|
$className = explode("\\", $className);
|
||||||
if (empty($object)) {
|
$className = array_pop($className);
|
||||||
continue;
|
$pattern = "/class[\n\s]+" . $className . "[\s\n]*\{/";
|
||||||
}
|
$status = preg_match($pattern, file_get_contents($file), $result);
|
||||||
if (!property_exists($object, 'classes') && !is_array($object->classes)) {
|
if ($status === 1) {
|
||||||
continue;
|
require_once $file;
|
||||||
}
|
break;
|
||||||
foreach ($object->classes as $classpath) {
|
|
||||||
require_once $path . PATH_SEP . $classpath;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
$searchFiles(PATH_PLUGINS);
|
||||||
|
};
|
||||||
|
spl_autoload_register($closure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user