Skip to content

FOUR-13834 | The Modified Date in Projects Isn’t Updated After Making Changes to the Project #6124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2024
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
8 changes: 8 additions & 0 deletions ProcessMaker/Http/Controllers/Api/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessTemplates;
use ProcessMaker\Models\Template;
use ProcessMaker\Traits\ProjectAssetTrait;

class TemplateController extends Controller
{
use ProjectAssetTrait;

protected array $types = [
'process' => [Process::class, ProcessTemplate::class, ProcessCategory::class, 'process_category_id', 'process_templates'],
];
Expand Down Expand Up @@ -143,6 +146,11 @@ public function create(string $type, Request $request)
} else {
$response = $this->template->create($type, $request);
}
if ($request->has('projects')) {
// Update 'updated_at' field for the project
$projectIds = explode(',', $request->input('projects'));
$this->updateProjectUpdatedAt($projectIds);
}
} elseif ($type === 'update-assets') {
$request['request'] = json_decode($request['request'], true);
$request['existingAssets'] = json_decode($request['existingAssets'], true);
Expand Down
22 changes: 22 additions & 0 deletions ProcessMaker/Traits/ProjectAssetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function syncProjectAsset($requestOrInteger, $assetModelClass)
try {
// Sync the project assets with the prepared project IDs
$this->projectAssets()->syncWithPivotValues($projectIds, ['asset_type' => $assetModelClass]);
$this->updateProjectUpdatedAt($projectIds);
} catch (Exception $e) {
throw new ProjectAssetSyncException('Error syncing project assets: ' . $e->getMessage());
}
Expand Down Expand Up @@ -81,4 +82,25 @@ public function getProjectsAttribute()

return json_encode([]);
}

/**
* Update the 'updated_at' field of projects.
*
* @param array|int $projectIds
* @return void
*/
public function updateProjectUpdatedAt($projectIds)
{
if (!class_exists(self::PROJECT_MODEL_CLASS)) {
return;
}

foreach ((array) $projectIds as $projectId) {
$project = self::PROJECT_MODEL_CLASS::find($projectId);

if ($project) {
$project->touch();
}
}
}
}