Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ProcessMaker/ImportExport/Exporters/ExporterBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ public function runExport()
}
}

public function runImport($existingAssetInDatabase = null)
public function runImport($existingAssetInDatabase = null, $importingFromTemplate = false)
{
$extensions = app()->make(Extension::class);
$extensions->runExtensions($this, 'preImport', $this->logger);
$this->logger->log('Running Import ' . static::class);
$this->import($existingAssetInDatabase);
$this->import($existingAssetInDatabase, $importingFromTemplate);
$extensions->runExtensions($this, 'postImport', $this->logger);
}

Expand Down
8 changes: 6 additions & 2 deletions ProcessMaker/ImportExport/Exporters/ProcessExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function export() : void
$this->exportSubprocesses();
}

public function import($existingAssetInDatabase = null) : bool
public function import($existingAssetInDatabase = null, $importingFromTemplate = false) : bool
{
if ($existingAssetInDatabase) {
$this->model = Process::where('id', $existingAssetInDatabase)->first();
Expand All @@ -90,7 +90,11 @@ public function import($existingAssetInDatabase = null) : bool
$process->manager_id = $dependent->model->id;
}

$this->associateCategories(ProcessCategory::class, 'process_category_id');
// Avoid associating the category from the manifest with processes imported from templates.
// Use the user-selected category instead.
if (!$importingFromTemplate) {
$this->associateCategories(ProcessCategory::class, 'process_category_id');
}

$this->importSignals();

Expand Down
6 changes: 3 additions & 3 deletions ProcessMaker/ImportExport/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function loadManifest()
return Manifest::fromArray($this->payload['export'], $this->options, $this->logger);
}

public function doImport($existingAssetInDatabase = null)
public function doImport($existingAssetInDatabase = null, $importingFromTemplate = false)
{
$this->logger->log('Starting Transaction');
DB::transaction(function () use ($existingAssetInDatabase) {
DB::transaction(function () use ($existingAssetInDatabase, $importingFromTemplate) {
// First, we save the model so we have IDs set for all assets
Schema::disableForeignKeyConstraints();

Expand Down Expand Up @@ -90,7 +90,7 @@ public function doImport($existingAssetInDatabase = null)
foreach ($this->manifest->all() as $exporter) {
if ($exporter->mode !== 'discard') {
$this->logger->log('Associating ' . get_class($exporter->model));
$exporter->runImport($existingAssetInDatabase);
$exporter->runImport($existingAssetInDatabase, $importingFromTemplate);
}
}

Expand Down
4 changes: 3 additions & 1 deletion ProcessMaker/Templates/ProcessTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ public function create($request) : JsonResponse
$options = new Options($postOptions);

$importer = new Importer($payload, $options);
$manifest = $importer->doImport();
$existingAssetsInDatabase = null;
$importingFromTemplate = true;
$manifest = $importer->doImport($existingAssetsInDatabase, $importingFromTemplate);
$rootLog = $manifest[$payload['root']]->log;
$processId = $rootLog['newId'];

Expand Down