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
18 changes: 7 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ defaults:
shell: bash
working-directory: ./api

# Note, jobs do not share the same working environment, whereas steps do. Also, jobs will run in parallel unless the 'needs' tag is used to flag a dependency
jobs:
php-build:
name: Checkout, build, test and lint PHP code
Expand All @@ -33,6 +32,9 @@ jobs:
with:
php-version: 7.3
tools: psalm:4
# Added extensions and coverage here so they are ready for the native run
extensions: mysqli, zip, xdebug
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate
Expand All @@ -49,17 +51,12 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

# CHANGED: Replaced php-actions/phpunit with native execution
# This runs the PHPUnit located in your vendor folder, avoiding the PHAR crash
- name: PHPUnit Tests
uses: php-actions/phpunit@v3
run: vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-text
env:
XDEBUG_MODE: coverage
with:
bootstrap: api/vendor/autoload.php
configuration: api/tests/phpunit.xml
php_extensions: xdebug mysqli zip
args: --coverage-text
php_version: 7.3
version: 9

- name: Run Psalm
run: psalm --output-format=github
Expand All @@ -77,8 +74,7 @@ jobs:
node-version: 18.x
- name: JavaScript build, lint and test
working-directory: ./client
# hack the output from the linting steps to avoid these stopping the builds - we are not going to get
# to a clean output without considerable effort, but it's useful to see the output
# hack the output from the linting steps to avoid these stopping the builds
run: |
cp src/js/config_sample.json src/js/config.json
node --version
Expand Down
4 changes: 2 additions & 2 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
}
],
"require": {
"apereo/phpcas": "1.3.8",
"apereo/phpcas": "1.6.1",
"ezyang/htmlpurifier": "4.12.0",
"firebase/php-jwt": "2.2.0",
"firebase/php-jwt": "6.0.0",
"jdorn/sql-formatter": "1.2.9",
"mpdf/mpdf": "8.1.2",
"ralouphie/getallheaders": "2.0.5",
Expand Down
1 change: 0 additions & 1 deletion api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@
$use_shipping_service_incoming_shipments = null;
$use_shipping_service_redirect = null;
$use_shipping_service_redirect_incoming_shipments = null;
$shipping_service_api_url = null;
$shipping_service_api_user = null;
$shipping_service_api_password = null;
$shipping_service_app_url = null;
Expand Down
8 changes: 7 additions & 1 deletion api/src/Authentication/Type/CAS.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ function check()
/**
* @psalm-suppress UndefinedConstant define in CAS.php
*/
phpCAS::client(CAS_VERSION_2_0, $cas_url, 443, '/cas');
$protocol = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$protocol = 'https';
}
$hostname = $_SERVER['HTTP_HOST'];
$service_base_url = $protocol . '://' . $hostname;
phpCAS::client(CAS_VERSION_2_0, $cas_url, 443, '/cas', $service_base_url);
phpCAS::setCasServerCACert($cacert);

try {
Expand Down
5 changes: 3 additions & 2 deletions api/src/Controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace SynchWeb\Controllers;

use Exception;
use JWT;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Slim\Slim;
use SynchWeb\Model\User;

Expand Down Expand Up @@ -280,7 +281,7 @@ private function checkForAndValidateAuthenticationToken()

try
{
$token = JWT::decode($jwt, $jwt_key, array('HS512'));
$token = JWT::decode($jwt, new Key($jwt_key, 'HS512'), array('HS512'));
$this->loginId = $token->data->login;
}
catch (\Exception $e)
Expand Down
16 changes: 3 additions & 13 deletions api/src/Downstream/Type/Dimple.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,12 @@ function _get_blobs() {
);
}

# This will break if dimple is run more than once on the same scalingid
# TODO: Change structure of MXMRRun to link to autoprocprogram
# https://jira.diamond.ac.uk/browse/SCI-7941
function _find_mrrun() {
if (!array_key_exists("scaling_id", $this->process['PARAMETERS'])) {
return;
}

$mrrun = $this->db->pq(
"SELECT mxmrrunid, processingstatus, processingmessage,
rvaluestart, rvalueend, rfreevaluestart, rfreevalueend
"SELECT m.mxmrrunid
FROM mxmrrun m
INNER JOIN autoprocprogram app
ON m.autoprocprogramid = app.autoprocprogramid
WHERE autoprocscalingid=:1",
array($this->process['PARAMETERS']["scaling_id"])
WHERE m.autoprocprogramid=:1",
array($this->autoprocprogramid)
);

if (!sizeof($mrrun)) {
Expand Down
80 changes: 80 additions & 0 deletions api/src/Downstream/Type/MetalId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace SynchWeb\Downstream\Type;

use SynchWeb\Downstream\DownstreamPlugin;
use SynchWeb\Downstream\DownstreamResult;

class MetalId extends DownstreamPlugin {
var $has_images = true;
var $friendlyname = 'Metal Id';
var $has_mapmodel = array(0, 0);
var $_mrrun;

function results() {
$blobs = $this->_get_blobs();
if (sizeof($blobs)) {
$headings = array('Peak', 'Height', 'XYZ');
} else {
$headings = array('No peaks found');
}
$peaks = array($headings);
foreach($blobs as $n => $blob) {
$peak = array($n+1, $blob['HEIGHT'], '('.$blob['X'].', '.$blob['Y'].', '.$blob['Z'].')');
array_push($peaks, $peak);
}
$dat = array();
$dat['BLOBS'] = sizeof($blobs);
$dat['PEAKS'] = $peaks;

$integrator = $this->_lookup_autoproc(
null,
$this->process['PARAMETERS']['scaling_id']
);
if ($integrator) {
$dat['PARENTAUTOPROCPROGRAM'] = $integrator['PROCESSINGPROGRAMS'];
$dat['PARENTAUTOPROCPROGRAMID'] = $integrator['AUTOPROCPROGRAMID'];
}

$results = new DownstreamResult($this);
$results->data = $dat;

return $results;
}

function _find_mrrun() {
$mrrun = $this->db->pq(
"SELECT m.mxmrrunid
FROM mxmrrun m
WHERE m.autoprocprogramid=:1",
array($this->autoprocprogramid)
);

if (!sizeof($mrrun)) {
return;
}

$this->_mrrun = $mrrun[0];
return true;
}

function _get_blobs() {
if (!$this->_find_mrrun()) {
return array();
}
return $this->db->pq(
"SELECT view1, filepath, x, y, z, height
FROM mxmrrunblob
WHERE mxmrrunid = :1
AND filepath is not NULL",
array($this->_mrrun["MXMRRUNID"])
);
}

function images($n = 0) {
$blobs = $this->_get_blobs();
if ($n < sizeof($blobs)) {
return $blobs[$n]["FILEPATH"] . '/' . $blobs[$n]["VIEW1"];
}
}
}
15 changes: 7 additions & 8 deletions api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ function _get_file($id, $file)
$response->headers->set("Content-Length", filesize($filename));
} elseif ($filesystem->exists($filename.'.gz')) {
$filename = $filename.'.gz';
if ($this->arg('download') == 1) {
// View log file, so unzip and serve
if ($this->has_arg('download') && $this->arg('download') < 3) {
// View/open file, so unzip and serve
$response = new Response(readgzfile($filename));
$this->set_mime_content($response, $file['FILENAME'], $id);
} else {
Expand Down Expand Up @@ -549,21 +549,20 @@ function set_mime_content($response, $filename, $prefix = null)

if (in_array($path_ext, array('html', 'htm'))) {
$response->headers->set("Content-Type", "text/html");
$this->_set_disposition_inline($response);
} elseif ($path_ext == 'pdf') {
$response->headers->set("Content-Type", "application/pdf");
$this->_set_disposition_attachment($response, $saved_filename);
} elseif ($path_ext == 'png') {
$response->headers->set("Content-Type", "image/png");
$this->_set_disposition_attachment($response, $saved_filename);
} elseif (in_array($path_ext, array('jpg', 'jpeg'))) {
$response->headers->set("Content-Type", "image/jpeg");
$this->_set_disposition_attachment($response, $saved_filename);
} elseif (in_array($path_ext, array('log', 'txt', 'error', 'LP', 'json', 'lsa'))) {
} elseif (in_array($path_ext, array('log', 'txt', 'error', 'LP', 'json', 'lsa', 'lst'))) {
$response->headers->set("Content-Type", "text/plain");
$this->_set_disposition_inline($response);
} else {
$response->headers->set("Content-Type", "application/octet-stream");
}
if ($this->has_arg('download') && $this->arg('download') < 3) {
$this->_set_disposition_inline($response);
} else {
$this->_set_disposition_attachment($response, $saved_filename);
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/Page/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function _enqueue()
);
$this->_send_zocalo_message($rabbitmq_zocalo_vhost, $message);

$this->_output(new \stdClass);
$this->_output('Job successfully submitted');
}

function _enqueue_downstream()
Expand Down Expand Up @@ -413,7 +413,7 @@ function _enqueue_downstream()

$this->_submit_zocalo_recipe($this->arg('RECIPE'), $parameters);

$this->_output(new \stdClass);
$this->_output('Job successfully submitted');
}

/*
Expand Down
Loading
Loading