FOUR-13983: Ensure "Uncategorized" process category exists during import by runyan-co · Pull Request #6165 · ProcessMaker/processmaker

Issue

In certain circumstances, running the php artisan package-pm-blocks:sync-pm-blocks artisan command would fail by throwing an uncaught exception (see output below). This was not consistent across instances as it would work for most, but a handful threw this exception.

  Illuminate\Database\Eloquent\ModelNotFoundException 

  No query results for model [ProcessMaker\Models\ProcessCategory].

  at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:619
    615▕         if (! is_null($model = $this->first($columns))) {
    616▕             return $model;
    617▕         }
    618▕ 
  ➜ 619▕         throw (new ModelNotFoundException)->setModel(get_class($this->model));
    620▕     }
    621▕ 
    622▕     /**
    623▕      * Execute the query and get the first result or call a callback.

  1   ProcessMaker/ImportExport/Exporters/ExporterBase.php:526
      Illuminate\Database\Eloquent\Builder::firstOrFail()
...

Reproduction Steps

  1. Navigate to the "Process Categories" tab on the "Processes" page in the "Designer" section of the admin dashboard.
  2. Find the "Uncategorized" default category and rename it to anything different (e.g. "Example Category")
  3. Try to run the php artisan package-pm-blocks:sync-pm-blocks command
  4. Notice it fails because it cannot find the default "Uncategorized" process category by name for one of the PM Block's internal subprocesses.

Solution

Recreate the default "Uncategorized" process category if it does not exist during the import.

How to Test

Run through the reproduction steps but there should be no failure and you should see the "Uncategorized" process category have a count of 3 on the "Process Categories" page.

CICD

ci:deploy
ci:next

Related Tickets & Packages

Code Review Checklist

  • I have pulled this code locally and tested it on my instance, along with any associated packages.
  • This code adheres to ProcessMaker Coding Guidelines.
  • This code includes a unit test or an E2E test that tests its functionality, or is covered by an existing test.
  • This solution fixes the bug reported in the original ticket.
  • This solution does not alter the expected output of a component in a way that would break existing Processes.
  • This solution does not implement any breaking changes that would invalidate documentation or cause existing Processes to fail.
  • This solution has been tested with enterprise packages that rely on its functionality and does not introduce bugs in those packages.
  • This code does not duplicate functionality that already exists in the framework or in ProcessMaker.
  • This ticket conforms to the PRD associated with this part of ProcessMaker.