Skip to content
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

Performance Improvements #6881

Merged
merged 197 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
d90442c
Add pm4-api-testing support
caleeli May 26, 2024
5abaad1
Update package code
caleeli May 26, 2024
6906dff
Update cicd
caleeli May 26, 2024
1bf4021
Remove dependency
caleeli May 26, 2024
e58be03
Initial deployment test and validation
caleeli May 26, 2024
544faf7
Deployment test
caleeli May 26, 2024
716e328
Deployment and validation
caleeli May 26, 2024
9793ae7
Test update package code
caleeli May 26, 2024
bc5a75c
Test update cicd
caleeli May 26, 2024
2e4743b
Test remove dependency
caleeli May 26, 2024
9fcc476
Filter pods
caleeli May 26, 2024
974095d
Test filter pods
caleeli May 26, 2024
c7d892a
Test deployment
caleeli May 26, 2024
3398fae
Deployment test and validation
caleeli May 26, 2024
cb4c329
Prepare for deployment: initial setup
caleeli May 26, 2024
1d77671
Test artisan commands for deployment
caleeli May 26, 2024
eaff679
Check all dependencies for updates and compatibility
caleeli May 26, 2024
fb47bc7
Validate dependencies for deployment process
caleeli May 26, 2024
0c25c75
Test deployment process with package updates
caleeli May 26, 2024
059087a
Check compatibility of updated packages
caleeli May 26, 2024
a3246df
Verify package integrity and functionality
caleeli May 26, 2024
2ab213b
Test execution of updated packages
caleeli May 26, 2024
e39658d
Update package versions for security patches
caleeli May 26, 2024
2b49f20
Fix issues with package update process
caleeli May 26, 2024
57fd6f7
Correct status handling in deployment process
caleeli May 26, 2024
23f7f23
Test new job configurations
caleeli May 26, 2024
4309e8e
Fix update job configuration for deployment
caleeli May 26, 2024
73700b2
Correct job1 configuration errors
caleeli May 26, 2024
d41c652
Fix issues in job2 configuration
caleeli May 26, 2024
2570b50
Run job test for deployment updates
caleeli May 26, 2024
27806b8
Initial integration test for CI/CD pipeline
caleeli May 26, 2024
090a615
Test integration details for continuous deployment
caleeli May 26, 2024
b87ea97
Update specific package to address vulnerabilities
caleeli May 26, 2024
307de4e
Add safe directory configuration for deployment
caleeli May 26, 2024
fb05f2a
Check system status post-deployment
caleeli May 26, 2024
8c90161
Update package dependencies to latest versions
caleeli May 26, 2024
e5f3e67
Optimize service restart process after deployment
caleeli May 26, 2024
6de9318
Add job to execute API tests based on PR description
caleeli May 27, 2024
f14cdbd
Update job condition to fix execution flow
caleeli May 27, 2024
2c45e03
Refine condition for job execution logic
caleeli May 27, 2024
b4b14dc
Add PR_BODY parameter for enhanced PR description handling
caleeli May 27, 2024
5d06269
Rebase code when updated
caleeli May 27, 2024
f631e2c
Rebase main code when updated
caleeli May 27, 2024
729d057
Improve code update on conflict or divergence
caleeli May 27, 2024
49fd9b1
Define v1.1 api routes
caleeli May 27, 2024
5e67352
File to register v1.1 routes
caleeli May 28, 2024
7657c0c
Base for tasks v1.1 controller
caleeli May 28, 2024
3d6bded
FOUR-15870 Implement Automated API Testing for Task Endpoint
julceslauhub May 28, 2024
6452861
Merge pull request #6890 from ProcessMaker/FOUR-15867
caleeli May 29, 2024
f3571fe
Implement v1.1 tasks endpoint
caleeli May 31, 2024
556452c
Merge pull request #6897 from ProcessMaker/FOUR-15868
caleeli May 31, 2024
756f234
Merge pull request #6897 from ProcessMaker/FOUR-15868
caleeli May 31, 2024
bc0d2d3
Add task screen endpoint
caleeli Jun 4, 2024
d2b24aa
Register endpoint
caleeli Jun 4, 2024
07c44e0
Add test for task screen endpoint
caleeli Jun 5, 2024
4d7ec3f
Reduce the size of response
caleeli Jun 6, 2024
46add45
Move resource screen functions into a trait
caleeli Jun 6, 2024
1ad9ba7
Update test
caleeli Jun 6, 2024
0eb08d8
Clean code
caleeli Jun 6, 2024
e78e6ee
Merge pull request #6913 from ProcessMaker/FOUR-15872
caleeli Jun 6, 2024
7626508
FOUR-15871 Optimize Interstitial to Reduce Redundant Task Calls
julceslauhub Jun 6, 2024
61ca014
Merge branch 'feature/FOUR-15739' of https://github.com/ProcessMaker/…
julceslauhub Jun 6, 2024
88086b4
Merge pull request #6914 from ProcessMaker/FOUR-15871
caleeli Jun 6, 2024
233a920
Merge pull request #6914 from ProcessMaker/FOUR-15871
caleeli Jun 6, 2024
d014e96
Post charts to PR
caleeli Jun 7, 2024
a4510cd
Absolute path of script
caleeli Jun 8, 2024
92137ea
test
caleeli Jun 8, 2024
8338912
test
caleeli Jun 8, 2024
ed6b24d
find script
caleeli Jun 8, 2024
b0280ca
Post comment from docker
caleeli Jun 8, 2024
585eb94
Fix
caleeli Jun 8, 2024
b2f1073
Move script to job
caleeli Jun 8, 2024
b0995e4
Use tee to show output in runtime
caleeli Jun 8, 2024
932374f
Add Nayra service as language
caleeli Jun 10, 2024
4fe8577
Add support Nayra to run scripts
caleeli Jun 11, 2024
2de84d5
Run scripts using nayra service
caleeli Jun 11, 2024
d9e7027
Add support for php-nayra to script editor
caleeli Jun 12, 2024
1689adf
Merge pull request #6923 from ProcessMaker/FOUR-16131
caleeli Jun 12, 2024
0c6ee70
Merge pull request #6942 from ProcessMaker/FOUR-15875
caleeli Jun 12, 2024
6fa08cf
Create PHP-Nayra executor
caleeli Jun 12, 2024
c90dd09
Add missing down method
caleeli Jun 12, 2024
c9d815c
FOUR-15873 Enhance Script Watcher Endpoint Performance
julceslauhub Jun 13, 2024
0904254
Merge pull request #6884 from ProcessMaker/FOUR-15870
caleeli Jun 13, 2024
68fe55c
Merge pull request #6947 from ProcessMaker/FOUR-15873
caleeli Jun 13, 2024
e7f1067
Merge remote-tracking branch 'origin/next' into feature/FOUR-15739
caleeli Jun 13, 2024
ac34ef4
Improve api-testing deploy
caleeli Jun 13, 2024
f0fcd73
Fix code style
caleeli Jun 14, 2024
2469a74
Enable apiClient 1.1
caleeli Jun 14, 2024
e0f1746
Add resources version 1.1
caleeli Jun 14, 2024
405b140
Fix issues
caleeli Jun 14, 2024
9469f0a
Fix code review issues
caleeli Jun 14, 2024
da6aa2f
Fix code review observations
caleeli Jun 14, 2024
521374d
Use constant for prefix
caleeli Jun 14, 2024
7e054a2
Improve the code to setup multiple version
caleeli Jun 14, 2024
e43fbe7
Merge pull request #6959 from ProcessMaker/FOUR-16001
caleeli Jun 14, 2024
edb6fa6
Fix code review
caleeli Jun 14, 2024
460c41b
Improve task screen endpoints
caleeli Jun 21, 2024
43ba79d
Bring up nayra container automatically
caleeli Jun 24, 2024
c401b9c
Add filter by status
caleeli Jun 24, 2024
1dde4b0
Fix status errors
caleeli Jun 24, 2024
77d650b
Remove debug code
caleeli Jun 24, 2024
14506b0
Remove commented code
caleeli Jun 25, 2024
fbb1fda
Add docker-executor-php-nayra:install
caleeli Jun 25, 2024
26b703a
Fix default docker config
caleeli Jun 26, 2024
234d310
Add pm4-api-testing support
caleeli May 26, 2024
5f6f1a4
Update package code
caleeli May 26, 2024
386fe4e
Update cicd
caleeli May 26, 2024
eef5acd
Remove dependency
caleeli May 26, 2024
e5cffc2
Initial deployment test and validation
caleeli May 26, 2024
c71b404
Deployment test
caleeli May 26, 2024
a1f655b
Deployment and validation
caleeli May 26, 2024
655a791
Test update package code
caleeli May 26, 2024
7d6362a
Test update cicd
caleeli May 26, 2024
8633543
Test remove dependency
caleeli May 26, 2024
ff5f597
Filter pods
caleeli May 26, 2024
700e4e7
Test filter pods
caleeli May 26, 2024
43cd358
Test deployment
caleeli May 26, 2024
e6cc7f4
Deployment test and validation
caleeli May 26, 2024
5962750
Prepare for deployment: initial setup
caleeli May 26, 2024
208b0d1
Test artisan commands for deployment
caleeli May 26, 2024
4f9082d
Check all dependencies for updates and compatibility
caleeli May 26, 2024
24c913c
Validate dependencies for deployment process
caleeli May 26, 2024
663e201
Test deployment process with package updates
caleeli May 26, 2024
88a649e
Check compatibility of updated packages
caleeli May 26, 2024
34c4acd
Verify package integrity and functionality
caleeli May 26, 2024
2f3c5b3
Test execution of updated packages
caleeli May 26, 2024
aed567d
Update package versions for security patches
caleeli May 26, 2024
3c55ec7
Fix issues with package update process
caleeli May 26, 2024
9a60740
Correct status handling in deployment process
caleeli May 26, 2024
8641a29
Test new job configurations
caleeli May 26, 2024
e596ff1
Fix update job configuration for deployment
caleeli May 26, 2024
36cd570
Correct job1 configuration errors
caleeli May 26, 2024
9f95b21
Fix issues in job2 configuration
caleeli May 26, 2024
1defbc6
Run job test for deployment updates
caleeli May 26, 2024
6ca0f61
Initial integration test for CI/CD pipeline
caleeli May 26, 2024
5b2ec70
Test integration details for continuous deployment
caleeli May 26, 2024
764665c
Update specific package to address vulnerabilities
caleeli May 26, 2024
7c4205c
Add safe directory configuration for deployment
caleeli May 26, 2024
41f1b2f
Check system status post-deployment
caleeli May 26, 2024
fa0eff9
Update package dependencies to latest versions
caleeli May 26, 2024
f17250d
Optimize service restart process after deployment
caleeli May 26, 2024
cf3b321
Add job to execute API tests based on PR description
caleeli May 27, 2024
f047c37
Update job condition to fix execution flow
caleeli May 27, 2024
f80d42e
Refine condition for job execution logic
caleeli May 27, 2024
3d5446a
Add PR_BODY parameter for enhanced PR description handling
caleeli May 27, 2024
ccc69f9
Rebase code when updated
caleeli May 27, 2024
ef80e98
Rebase main code when updated
caleeli May 27, 2024
3294e25
Improve code update on conflict or divergence
caleeli May 27, 2024
5cafda0
Define v1.1 api routes
caleeli May 27, 2024
93abfdf
File to register v1.1 routes
caleeli May 28, 2024
129d53f
Base for tasks v1.1 controller
caleeli May 28, 2024
4926413
FOUR-15870 Implement Automated API Testing for Task Endpoint
julceslauhub May 28, 2024
04ef3a6
Implement v1.1 tasks endpoint
caleeli May 31, 2024
53a761d
Add task screen endpoint
caleeli Jun 4, 2024
f815a2f
Register endpoint
caleeli Jun 4, 2024
7f6d63b
Add test for task screen endpoint
caleeli Jun 5, 2024
91b8a72
Reduce the size of response
caleeli Jun 6, 2024
3522b9a
Move resource screen functions into a trait
caleeli Jun 6, 2024
697de0d
Update test
caleeli Jun 6, 2024
b98ecc6
Clean code
caleeli Jun 6, 2024
77f5218
FOUR-15871 Optimize Interstitial to Reduce Redundant Task Calls
julceslauhub Jun 6, 2024
057ace5
Post charts to PR
caleeli Jun 7, 2024
4190bb1
Absolute path of script
caleeli Jun 8, 2024
e8f563a
test
caleeli Jun 8, 2024
0e6b22a
test
caleeli Jun 8, 2024
b7e2383
find script
caleeli Jun 8, 2024
7282068
Post comment from docker
caleeli Jun 8, 2024
4790475
Fix
caleeli Jun 8, 2024
461a049
Move script to job
caleeli Jun 8, 2024
bfa82ce
Add Nayra service as language
caleeli Jun 10, 2024
0513c6c
Add support Nayra to run scripts
caleeli Jun 11, 2024
5f65a15
Run scripts using nayra service
caleeli Jun 11, 2024
b1c2993
Add support for php-nayra to script editor
caleeli Jun 12, 2024
ded5593
Create PHP-Nayra executor
caleeli Jun 12, 2024
494fa17
Add missing down method
caleeli Jun 12, 2024
e2ff62f
FOUR-15873 Enhance Script Watcher Endpoint Performance
julceslauhub Jun 13, 2024
c9fd11f
Fix code style
caleeli Jun 14, 2024
78611dc
Enable apiClient 1.1
caleeli Jun 14, 2024
3337704
Add resources version 1.1
caleeli Jun 14, 2024
e5bd3a7
Fix issues
caleeli Jun 14, 2024
22414b2
Fix code review issues
caleeli Jun 14, 2024
7cc9df6
Fix code review observations
caleeli Jun 14, 2024
2fd192e
Use constant for prefix
caleeli Jun 14, 2024
b8f822b
Improve the code to setup multiple version
caleeli Jun 14, 2024
12df1b0
Fix code review
caleeli Jun 14, 2024
266c1b8
Updating feature branch
julceslauhub Jun 27, 2024
f623588
Merge pull request #6983 from ProcessMaker/FOUR-16132
caleeli Jun 28, 2024
46b7378
FOUR-15876 Improve Saved Search Get Records Endpoint
julceslauhub Jun 27, 2024
2a80ed7
FOUR-16002 Improve show request complete view
julceslauhub Jun 28, 2024
a4b42b1
Merge pull request #7003 from ProcessMaker/FOUR-16002
caleeli Jun 28, 2024
4e46eef
Merge pull request #6998 from ProcessMaker/FOUR-15876
caleeli Jun 28, 2024
e76bace
FOUR-16909 Rebase and Redeploy the ci server for Performance Improvem…
julceslauhub Jul 1, 2024
19b0d13
Add support to configure docker network
caleeli Jul 4, 2024
2e4473f
CICD tests requires a docker network to run nayra
caleeli Jul 4, 2024
c7b9e9f
Merge remote-tracking branch 'origin/next' into feature/FOUR-15739
caleeli Jul 4, 2024
9da2baa
Clean code to run api test in cicd
caleeli Jul 4, 2024
c6ae5d0
fix condition in deployment
caleeli Jul 5, 2024
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
72 changes: 71 additions & 1 deletion .github/workflows/deploy-pm4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
BUILD_BASE: ${{ (contains(github.event.pull_request.body, 'ci:build-base') || github.event_name == 'schedule') && '1' || '0' }}
BASE_IMAGE: ${{ secrets.REGISTRY_HOST }}/processmaker/processmaker:base
K8S_BRANCH: ${{ contains(github.event.pull_request.body, 'ci:next') && 'next' || 'develop' }}
K8S_BRANCH: ${{ contains(github.event.pull_request.body, 'ci:next') && 'next' || 'develop' }}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -145,6 +145,76 @@ jobs:
run: |
echo "Instance URL: '${INSTANCE_URL}'"
bash argocd/gh_comment.sh "$CI_PROJECT" "$pull_req_id"
runAPITest:
name: Run API Tests
needs: [deployEKS]
if: contains(github.event.pull_request.body, 'ci:api-test')
runs-on: self-hosted
steps:
- name: Clone private repository
run: |
git clone --depth 1 -b eng "https://$GITHUB_TOKEN@github.com/ProcessMaker/argocd.git" argocd
- name: Install pm4-tools
run: |
git clone --depth 1 -b "$K8S_BRANCH" "https://$GITHUB_TOKEN@github.com/ProcessMaker/pm4-k8s-distribution.git" pm4-k8s-distribution
echo "versionHelm=$(grep "version:" "pm4-k8s-distribution/charts/enterprise/Chart.yaml" | awk '{print $2}' | sed 's/\"//g')" >> $GITHUB_ENV
cd pm4-k8s-distribution/images/pm4-tools
composer install --no-interaction
cd ..
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID1 }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY1 }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Authenticate with Amazon EKS
run: aws eks update-kubeconfig --region us-east-1 --name pm4-eng
- name: Run the API tests
run: |
cd argocd
deploy=$(echo -n ${{env.IMAGE_TAG}} | md5sum | head -c 10)
namespace="ci-$deploy-ns-pm4"
pr_body=$(jq -r .pull_request.body < "$GITHUB_EVENT_PATH" | base64)
kubectl get pods --namespace=$namespace
pod_names=$(kubectl get pods --namespace=$namespace --field-selector=status.phase=Running -o jsonpath="{.items[*].metadata.name}" | tr ' ' '\n' | grep -E '(-processmaker-scheduler-)')
for pod in $pod_names; do
code='
has_processmaker=$(ls /opt | grep processmaker)
has_sudo=$(ls /usr/bin | grep sudo)
has_php=$(ls /usr/bin | grep php)
if [ ! -z "$has_processmaker" ] && [ ! -z "$has_sudo" ] && [ ! -z "$has_php" ]; then
echo $pr_body | base64 -d > /tmp/pr_body
cd /opt/processmaker
sudo -u nginx php artisan pm4-api-testing:run --body="$pr_body"
else
exit 1
fi'
kubectl exec -n $namespace $pod -- /bin/sh -c "pr_body='${pr_body}';${code}" | tee /tmp/comment.md && break || true
done
# Send the content of /tmp/comment.md as a PR comment
MESSAGE=$(cat /tmp/comment.md)
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY=${{ github.repository }}
PR_NUMBER=$(jq -r .number < "$GITHUB_EVENT_PATH")

if [ -z "$PR_NUMBER" ]; then
echo "The PR number is not available. Make sure this script is executed in a context of Pull Request."
exit 1
fi

URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments"
json_payload=$(jq -n --arg message "$MESSAGE" '{"body": $message}')

curl -s \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
-d "$json_payload" \
"${URL}"
deleteEKS:
name: Delete Instance
if: github.event.action == 'closed'
Expand Down
13 changes: 12 additions & 1 deletion ProcessMaker/Console/Commands/BuildScriptExecutors.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ProcessMaker\Exception\InvalidDockerImageException;
use ProcessMaker\Facades\Docker;
use ProcessMaker\Models\ScriptExecutor;
use ProcessMaker\ScriptRunners\Base;

class BuildScriptExecutors extends Command
{
Expand Down Expand Up @@ -157,6 +158,16 @@ public function buildExecutor()
$command = Docker::command() .
" build --build-arg SDK_DIR=./sdk -t {$image} -f {$packagePath}/Dockerfile.custom {$packagePath}";

$this->execCommand($command);

$isNayra = $scriptExecutor->language === Base::NAYRA_LANG;
if ($isNayra) {
Base::bringUpNayraExecutor($this, $image);
}
}

public function execCommand(string $command)
{
if ($this->userId) {
$this->runProc(
$command,
Expand Down Expand Up @@ -185,7 +196,7 @@ public function info($text, $verbosity = null)
parent::info($text, $verbosity);
}

private function sendEvent($output, $status)
public function sendEvent($output, $status)
{
if ($this->userId) {
event(new BuildScriptExecutor($output, $this->userId, $status));
Expand Down
46 changes: 46 additions & 0 deletions ProcessMaker/Console/Commands/DockerExecutorPhpNayra.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace ProcessMaker\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use ProcessMaker\Models\ScriptExecutor;
use ProcessMaker\ScriptRunners\Base;

class DockerExecutorPhpNayra extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'docker-executor-php-nayra:install';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Install and configure Docker Executor PHP Nayra';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$exists = ScriptExecutor::where('language', Base::NAYRA_LANG)->exists();
if (!$exists) {
ScriptExecutor::install([
'language' => Base::NAYRA_LANG,
'title' => 'Nayra (µService)',
'description' => 'Nayra (µService) Executor',
'config' => '',
]);
}

// Build the instance image. This is the same as if you were to build it from the admin UI
Artisan::call('processmaker:build-script-executor ' . Base::NAYRA_LANG . ' --rebuild');
}
}
11 changes: 11 additions & 0 deletions ProcessMaker/Events/ActivityAssigned.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ public function getProcessRequestToken()
{
return $this->processRequestToken;
}

/**
* Get data
*/
public function getData(): array
{
return [
'payloadUrl' => $this->payloadUrl,
'element_type' => $this->processRequestToken->element_type,
];
}
}
12 changes: 11 additions & 1 deletion ProcessMaker/Events/ProcessUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;

class ProcessUpdated implements ShouldBroadcastNow
{
Expand All @@ -17,19 +18,28 @@ class ProcessUpdated implements ShouldBroadcastNow

public $event;

public $tokenId;

public $elementType;

private $processRequest;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(ProcessRequest $processRequest, $event)
public function __construct(ProcessRequest $processRequest, $event, TokenInterface $token = null)
{
$this->payloadUrl = route('api.requests.show', ['request' => $processRequest->getKey()]);
$this->event = $event;

$this->processRequest = $processRequest;

if ($token) {
$this->tokenId = $token->getId();
$this->elementType = $token->element_type;
}
}

/**
Expand Down
102 changes: 102 additions & 0 deletions ProcessMaker/Http/Controllers/Api/V1_1/TaskController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

declare(strict_types=1);

namespace ProcessMaker\Http\Controllers\Api\V1_1;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Http\Resources\V1_1\TaskInterstitialResource;
use ProcessMaker\Http\Resources\V1_1\TaskResource;
use ProcessMaker\Http\Resources\V1_1\TaskScreen;
use ProcessMaker\Models\ProcessRequestToken;

class TaskController extends Controller
{
protected $defaultFields = [
'id',
'element_id',
'element_name',
'element_type',
'status',
'due_at',
];

/**
* Display a listing of the resource.
*/
public function index()
{
$query = ProcessRequestToken::select($this->defaultFields)
->where('element_type', 'task');

$this->processFilters(request(), $query);
$pagination = $query->paginate();
$perPage = $pagination->perPage();
$page = $pagination->currentPage();
$lastPage = $pagination->lastPage();
return [
'data' => $pagination->items(),
'meta' => [
'total' => $pagination->total(),
'perPage' => $pagination->perPage(),
'currentPage' => $pagination->currentPage(),
'lastPage' => $pagination->lastPage(),
'count' => $pagination->count(),
'from' => $perPage * ($page - 1) + 1,
'last_page' => $lastPage,
'path' => '/',
'per_page' => $perPage,
'to' => $perPage * ($page - 1) + $perPage,
'total_pages' => ceil($pagination->count() / $perPage),
],
];
}

private function processFilters(Request $request, Builder $query)
{
if ($request->has('process_request_id')) {
$query->where('process_request_id', $request->input('process_request_id'));
}
if ($request->has('status')) {
$query->where('status', $request->input('status'));
}
}

public function show(ProcessRequestToken $task)
{
$resource = TaskResource::preprocessInclude(request(), ProcessRequestToken::where('id', $task->id));
return $resource->toArray(request());
}

public function showScreen($taskId)
{
$task = ProcessRequestToken::select(
array_merge($this->defaultFields, ['process_request_id', 'process_id'])
)->findOrFail($taskId);
$response = new TaskScreen($task);
$response = response($response->toArray(request())['screen'], 200);
$now = time();
// screen cache time
$cacheTime = config('screen_task_cache_time', 86400);
$response->headers->set('Cache-Control', 'max-age=' . $cacheTime . ', must-revalidate, public');
$response->headers->set('Expires', gmdate('D, d M Y H:i:s', $now + $cacheTime) . ' GMT');
return $response;
}

public function showInterstitial($taskId)
{
$task = ProcessRequestToken::select(
array_merge($this->defaultFields, ['process_request_id', 'process_id'])
)->findOrFail($taskId);
$response = new TaskInterstitialResource($task);
$response = response($response->toArray(request())['screen'], 200);
$now = time();
// screen cache time
$cacheTime = config('screen_task_cache_time', 86400);
$response->headers->set('Cache-Control', 'max-age=' . $cacheTime . ', must-revalidate, public');
$response->headers->set('Expires', gmdate('D, d M Y H:i:s', $now + $cacheTime) . ' GMT');
return $response;
}
}
26 changes: 0 additions & 26 deletions ProcessMaker/Http/Resources/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,6 @@ private function addAssignableUsers(&$array, $include)
}
}

private function loadUserRequestPermission(ProcessRequest $request, User $user, array $permissions)
{
$permissions[] = [
'process_request_id' => $request->id,
'allowed' => $user ? $user->can('view', $request) : false,
];

if ($request->parentRequest && $user) {
$permissions = $this->loadUserRequestPermission($request->parentRequest, $user, $permissions);
}

return $permissions;
}

/**
* Add the active users to the list of assigned users
*
Expand Down Expand Up @@ -161,16 +147,4 @@ private function addActiveAssignedGroupMembers(array $groups, array $assignedUse
{
return (new Process)->getConsolidatedUsers($groups, $assignedUsers);
}

private function getData()
{
if ($this->loadedData) {
return $this->loadedData;
}
$dataManager = new DataManager();
$task = $this->resource->loadTokenInstance();
$this->loadedData = $dataManager->getData($task);

return $this->loadedData;
}
}
19 changes: 19 additions & 0 deletions ProcessMaker/Http/Resources/V1_1/TaskInterstitialResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ProcessMaker\Http\Resources\V1_1;

use Illuminate\Http\Request;

class TaskInterstitialResource extends TaskResource
{
/**
* Transform the resource into an array.
*
* @param Request
* @return array
*/
public function toArray($request)
{
return $this->includeInterstitial();
}
}
Loading
Loading