Skip to content

Commit

Permalink
Merge branch 'release-2024-fall' into observation/FOUR-19270
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacornelius committed Oct 22, 2024
2 parents abf4319 + 6ed946d commit ec90691
Show file tree
Hide file tree
Showing 168 changed files with 7,498 additions and 6,425 deletions.
18 changes: 17 additions & 1 deletion ProcessMaker/BuildSdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function run()
public function setUserId($userId)
{
if (!is_numeric($userId)) {
throw new \Exception('User id must be a number');
throw new Exception('User id must be a number');
}
$this->userId = $userId;
}
Expand Down Expand Up @@ -236,6 +236,22 @@ private function fixErroneousCode($folder)
"sed -i -E 's/ProcessMaker\\\Models\\\/ProcessMaker\\\\\\\Models\\\\\\\/g' {} \;"
);
}

if ($this->lang === 'php') {
$content = file_get_contents("{$folder}/lib/ObjectSerializer.php");
$line = 'if (in_array($class, [\'DateTime';
$insertAbove = '
if ($class === "mixed") {
$jsonObj = json_decode($data, true);
if ($jsonObj === null && json_last_error() !== JSON_ERROR_NONE) {
return $data;
}
return $jsonObj;
}
';
$content = str_replace($line, $insertAbove . "\n\n" . $line, $content);
file_put_contents("{$folder}/lib/ObjectSerializer.php", $content);
}
}

private function addMissingDependency($folder)
Expand Down
8 changes: 6 additions & 2 deletions ProcessMaker/Console/Commands/ProcessmakerClearRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace ProcessMaker\Console\Commands;

use Illuminate\Console\Command;
use ProcessMaker\Models\CaseParticipated;
use ProcessMaker\Models\CaseStarted;
use ProcessMaker\Models\Comment;
use ProcessMaker\Models\Media;
use ProcessMaker\Models\ProcessCollaboration;
Expand All @@ -13,7 +15,7 @@

class ProcessmakerClearRequests extends Command
{
const message = 'Are you sure you\'d like to remove all requests and related data? Make sure you have backed up your database as this cannot be undone.';
const message = 'Are you sure you\'d like to remove all requests, cases and related data? Make sure you have backed up your database as this cannot be undone.';

/**
* The name and signature of the console command.
Expand All @@ -27,7 +29,7 @@ class ProcessmakerClearRequests extends Command
*
* @var string
*/
protected $description = 'Clear all requests / task data';
protected $description = 'Clear all requests / cases / task data';

/**
* Execute the console command.
Expand All @@ -45,6 +47,8 @@ public function handle()
Comment::where('commentable_type', ProcessRequestToken::class)->delete();
ProcessCollaboration::query()->truncate();
ProcessRequest::query()->truncate();
CaseParticipated::query()->truncate();
CaseStarted::query()->truncate();
}
}
}
68 changes: 68 additions & 0 deletions ProcessMaker/Console/Commands/UpdateCommentsCaseNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace ProcessMaker\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Models\Comment;

class UpdateCommentsCaseNumber extends Command
{
const CHUNK_SIZE = 5000;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'processmaker:update-comments-case-number';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Update the column case_number in comments';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// Update the case_number with the corresponding value in the table comments
$chunkSize = self::CHUNK_SIZE;
// Update the comments related to ProcessRequestToken
DB::table('comments')
->leftJoin('process_request_tokens', 'comments.commentable_id', '=', 'process_request_tokens.id')
->leftJoin('process_requests', 'process_request_tokens.process_request_id', '=', 'process_requests.id')
->where('comments.commentable_type', 'ProcessMaker\\Models\\ProcessRequestToken')
->whereNull('comments.case_number')
->select('comments.id', 'process_requests.case_number')
->chunkById($chunkSize, function ($comments) {
foreach ($comments as $comment) {
// Update the comments.case_number with ptrocess_requests.case_number
DB::table('comments')
->where('id', $comment->id)
->update(['case_number' => $comment->case_number]);
}
});
// Update the comments related to ProcessRequest
DB::table('comments')
->leftJoin('process_requests', 'comments.commentable_id', '=', 'process_requests.id')
->where('comments.commentable_type', 'ProcessMaker\\Models\\ProcessRequest')
->whereNull('comments.case_number')
->select('comments.id', 'process_requests.case_number')
->chunkById($chunkSize, function ($comments) {
foreach ($comments as $comment) {
// Update the comments.case_number with ptrocess_requests.case_number
DB::table('comments')
->where('id', $comment->id)
->update(['case_number' => $comment->case_number]);
}
});

return $this->info('Comments case_number updated successfully');
}
}
28 changes: 28 additions & 0 deletions ProcessMaker/Facades/ScreenCompiledManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace ProcessMaker\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static void storeCompiledContent(string $screenKey, mixed $compiledContent)
* @method static mixed|null getCompiledContent(string $screenKey)
* @method static void clearCompiledAssets()
* @method static string createKey(string $processId, string $processVersionId, string $language, string $screenId, string $screenVersionId)
* @method static int getLastScreenVersionId()
* @method static void clearProcessScreensCache(string $processId)
*
* @see \ProcessMaker\Managers\ScreenCompiledManager
*/
class ScreenCompiledManager extends Facade
{
/**
* Get the registered name of the component in the service container.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'compiledscreen';
}
}
28 changes: 28 additions & 0 deletions ProcessMaker/Http/Controllers/Api/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public function store(Request $request)
$this->authorizeComment($request);

$data['user_id'] = Auth::user()->id;
// Get the case_number if was not send
$caseNumber = $request->input('case_number', null);
if (is_null($caseNumber)) {
$caseNumber = $this->getCaseNumber($request);
}
$data['case_number'] = $caseNumber;
$request->merge($data);
$request->validate(Comment::rules());

Expand Down Expand Up @@ -194,6 +200,12 @@ public function update(Comment $comment, Request $request)
abort(403);
}
$data['user_id'] = Auth::user()->id;
// Get the case_number if was not send
$caseNumber = $request->input('case_number', null);
if (is_null($caseNumber)) {
$caseNumber = $this->getCaseNumber($request);
}
$data['case_number'] = $caseNumber;
$request->merge($data);
$request->validate(Comment::rules());

Expand Down Expand Up @@ -227,4 +239,20 @@ public function destroy(Comment $comment)

return response([], 204);
}

private function getCaseNumber(Request $request)
{
$requestId = null;
$commentableType = $request->input('commentable_type');
if ($commentableType === 'ProcessMaker\Models\ProcessRequestToken') {
$requestId = ProcessRequestToken::where('id', $request->input('commentable_id'))->value('process_request_id');
} elseif ($commentableType === 'ProcessMaker\Models\ProcessRequest') {
$requestId = $request->input('commentable_id');
}
if ($requestId) {
return ProcessRequest::where('id', $requestId)->value('case_number');
}

return null;
}
}
29 changes: 12 additions & 17 deletions ProcessMaker/Http/Controllers/Api/DevLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Validation\Rule;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Http\Resources\ApiCollection;
use ProcessMaker\Jobs\DevLinkInstall;
use ProcessMaker\Models\Bundle;
use ProcessMaker\Models\DevLink;
use ProcessMaker\Models\Setting;
Expand Down Expand Up @@ -91,6 +92,10 @@ public function localBundles(Request $request)
$bundlesQuery->published();
}

if ($request->has('editable')) {
$bundlesQuery->editable();
}

$filter = $request->input('filter', '');
if (!empty($filter)) {
$filter = '%' . $filter . '%';
Expand Down Expand Up @@ -128,7 +133,6 @@ public function createBundle(Request $request)
$bundle = new Bundle();
$bundle->name = $request->input('name');
$bundle->published = (bool) $request->input('published', false);
$bundle->locked = (bool) $request->input('locked', false);
$bundle->version = 1;
$bundle->saveOrFail();

Expand All @@ -139,7 +143,6 @@ public function updateBundle(Request $request, Bundle $bundle)
{
$bundle->name = $request->input('name');
$bundle->published = (bool) $request->input('published', false);
$bundle->locked = (bool) $request->input('locked', false);
$bundle->version = $bundle->version + 1;
$bundle->saveOrFail();

Expand All @@ -151,9 +154,14 @@ public function deleteBundle(Bundle $bundle)
$bundle->delete();
}

public function installRemoteBundle(DevLink $devLink, $remoteBundleId)
public function installRemoteBundle(Request $request, DevLink $devLink, $remoteBundleId)
{
return $devLink->installRemoteBundle($remoteBundleId);
DevLinkInstall::dispatch(
$request->user()->id,
$devLink->id,
$remoteBundleId,
'update'
);
}

public function exportLocalBundle(Bundle $bundle)
Expand All @@ -170,19 +178,6 @@ public function exportLocalAsset(Request $request)

public function addAsset(Request $request, Bundle $bundle)
{
$request->validate([
'type' => ['required', 'string'],
'id' => Rule::unique('bundle_assets', 'asset_id')->where(function ($query) use ($request) {
$query->where([
'asset_id' => $request->input('id'),
'asset_type' => $request->input('type'),
]);
}),
],
[
'id.unique' => __('Asset already exists in bundle'),
]);

$asset = $request->input('type')::findOrFail($request->input('id'));
$bundle->addAsset($asset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ public function update(ProcessRequest $request, Request $httpRequest)
'commentable_id' => $request->id,
'subject' => 'Data edited',
'body' => $user_name . ' ' . $text,
'case_number' => isset($request->case_number) ? $request->case_number : null,
]);
} else {
$httpRequest->validate(ProcessRequest::rules($request));
Expand Down Expand Up @@ -629,6 +630,7 @@ private function completeRequest(ProcessRequest $request)
'commentable_id' => $request->id,
'subject' => __('Process Manually Completed'),
'body' => $user->fullname . ' ' . __('manually completed the request from an error state'),
'case_number' => isset($request->case_number) ? $request->case_number : null,
]);
}

Expand Down Expand Up @@ -842,7 +844,7 @@ public function endEventDestination(ProcessRequest $request)

/**
* This endpoint returns requests by case number
*
*
* @param Request $request
*
* @return ApiCollection
Expand All @@ -863,14 +865,14 @@ public function getRequestsByCase(Request $request, User $user = null)
]);

$query = ProcessRequest::forUser($user);

// Filter by case_number
$query->filterByCaseNumber($request);

// Apply ordering only if a valid order_by field is provided
$query->applyOrdering($request);
$response = $query->applyPagination($request);

// Get activeTasks and participants
$response = $response->map(function ($processRequest) use ($request) {
return new ProcessRequestResource($processRequest);
Expand Down
Loading

0 comments on commit ec90691

Please sign in to comment.