Skip to content

Commit

Permalink
CAKEPHP5 upgrade fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Sep 12, 2025
1 parent b04aba0 commit 5861c82
Show file tree
Hide file tree
Showing 47 changed files with 229 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function beforeRender(\Cake\Event\EventInterface $event) {
if(!empty($vv_obj->api_source_id)) {
$apiSource = $this->ApiSourceEndpoints->ApiSources->get(
$vv_obj->api_source_id,
['contain' => 'ExternalIdentitySources']
contain: 'ExternalIdentitySources'
);

$this->set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ protected function mapApiToRegistry(string $model, array $attributes): array {
*/

public function remove(int $id, string $sorLabel, string $sorId): bool {
// We call this remove() so as not to interfere with the default table::delete().
$apiSource = $this->get($id, ['contain' => ['ExternalIdentitySources']]);

// Pull our configuration
$apiSource = $this->get($id, ['contain' => ['ExternalIdentitySources']]);
$apiSource = $this->get($id, contain: ['ExternalIdentitySources']);

// Like upsert(), we don't really need $sorLabel, but we check it for
// consistency with upsert() (which also doesn't really need it).
Expand Down Expand Up @@ -413,7 +410,7 @@ public function upsert(
$ret = [];

// Pull our configuration
$apiSource = $this->get($id, ['contain' => ['ExternalIdentitySources']]);
$apiSource = $this->get($id, contain: ['ExternalIdentitySources']);

// Strictly speaking we don't need $sorLabel since we know which configuration
// to use from the ApiSource ID, and $sorLabel might not be unique across COs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ protected function syncEntity(
*/

public function syncReferenceData(int $id, string $dataSource='targetdb') {
$spcfg = $this->get($id, ['contain' => ['ProvisioningTargets']]);
$spcfg = $this->get($id, contain: ['ProvisioningTargets']);

$this->Servers->SqlServers->connect($spcfg->server_id, $dataSource);

Expand Down
2 changes: 1 addition & 1 deletion app/plugins/CoreAssigner/src/Lib/Jobs/SqlAssignerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function run(

$this->ia = $this->IdentifierAssignments->get(
$parameters['identifier_assignment_id'],
['contain' => ['SqlAssigners', 'IdentifierTypes']]
contain: ['SqlAssigners', 'IdentifierTypes']
);

if($this->ia->plugin != 'CoreAssigner.SqlAssigners') {
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/CoreJob/src/Lib/Jobs/SyncJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected function getRunContext(

$this->runContext->eis = $this->runContext->EISTable->get(
$eisId,
['contain' => $this->runContext->EISTable->getPluginRelations()]
contain: $this->runContext->EISTable->getPluginRelations()
);
}

Expand Down
5 changes: 4 additions & 1 deletion app/plugins/CoreServer/src/Model/Table/MatchServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public function initialize(array $config): void {
$this->setTableType(\App\Lib\Enum\TableTypeEnum::Configuration);

// Define associations
$this->belongsTo('Servers');
// Avoid redefining the association if the parent already set it
if (!$this->hasAssociation('Servers')) {
$this->belongsTo('Servers');
}
$this->hasMany('CoreServer.MatchServerAttributes')
->setDependent(true)
->setCascadeCallbacks(true);
Expand Down
6 changes: 4 additions & 2 deletions app/plugins/CoreServer/src/Model/Table/Oauth2ServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ public function initialize(array $config): void {
$this->setTableType(\App\Lib\Enum\TableTypeEnum::Configuration);

// Define associations
// XXX this is defined in HttpServersTable
// $this->belongsTo('Servers');
// Avoid redefining the association if the parent already set it
if (!$this->hasAssociation('Servers')) {
$this->belongsTo('Servers');
}

$this->setDisplayField('hostname');

Expand Down
2 changes: 1 addition & 1 deletion app/plugins/CoreServer/src/Model/Table/SqlServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function connect(int $serverId, string $name): bool {
// which is basically what the SQL Provisioner does.

// Pull our configuration via the parent Server object.
$server = $this->Servers->get($serverId, ['contain' => ['SqlServers']]);
$server = $this->Servers->get($serverId, contain: ['SqlServers']);

$dbmap = [
RdbmsTypeEnum::MariaDB => 'Mysql',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function dispatch(string $id) {

// Pull our configuration

$envSource = $this->EnvSourceCollectors->get((int)$id, ['contain' => ['ExternalIdentitySources' => 'EnvSources']]);
$envSource = $this->EnvSourceCollectors->get((int)$id, contain: ['ExternalIdentitySources' => 'EnvSources']);

try {
$vars = $this->EnvSourceCollectors->parse($envSource->external_identity_source->env_source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function hydrate(int $id, \App\Model\Entity\Petition $petition) {

$eis = $ExtIdentitySources->get(
$cfg->external_identity_source_id,
['contain' => 'EnvSources']
contain: 'EnvSources'
);

$eisrecord = $EnvSources->retrieve($eis, $pei->env_source_identity->source_key);
Expand Down Expand Up @@ -514,7 +514,7 @@ public function verifiableEmailAddresses(

$eis = $this->ExternalIdentitySources->get(
$config->external_identity_source_id,
['contain' => 'Pipelines']
contain: 'Pipelines'
);

$defaultVerified = isset($eis->pipeline->sync_verify_email_addresses)
Expand Down
3 changes: 3 additions & 0 deletions app/src/Command/JobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
use Cake\Utility\Security;
use App\Lib\Enum\JobStatusEnum;
use App\Lib\Events\CoIdEventListener;
use Cake\ORM\Locator\LocatorAwareTrait;

class JobCommand extends BaseCommand
{
use LocatorAwareTrait;

/**
* Register command specific options.
*
Expand Down
10 changes: 9 additions & 1 deletion app/src/Command/NotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@
use Cake\Console\BaseCommand;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\TableRegistry;

class NotificationCommand extends BaseCommand
{
use LocatorAwareTrait;

/**
* Register command specific options.
*
Expand Down Expand Up @@ -202,6 +206,10 @@ public function execute(Arguments $args, ConsoleIo $io)
$io->out("- Recipient Person ID: " . $recipientPersonId);
$io->out("- Recipient Group ID: " . $recipientGroupId);

$MessageTemplates = TableRegistry::getTableLocator()->get('MessageTemplates');
$template = $MessageTemplates->get($args->getOption('messageTemplateId'));


$notificationIds = $Notifications->register(
subjectPersonId: $subjectPersonId,
subjectGroupId: $subjectGroupId,
Expand All @@ -210,7 +218,7 @@ public function execute(Arguments $args, ConsoleIo $io)
recipientGroupId: $recipientGroupId,
action: $args->getOption('action'),
comment: $args->getOption('comment'),
messageTemplateId: (int)$args->getOption('messageTemplateId'),
messageTemplate: $template,
source: $args->getOption('source'),
mustResolve: $args->getOption('mustResolve')
);
Expand Down
3 changes: 3 additions & 0 deletions app/src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
use Cake\Utility\Security;
use App\Lib\Enum\PermissionEnum;
use App\Lib\Enum\SuspendableStatusEnum;
use Cake\ORM\Locator\LocatorAwareTrait;

class SetupCommand extends BaseCommand
{
use LocatorAwareTrait;

/**
* Register command specific options.
*
Expand Down
3 changes: 3 additions & 0 deletions app/src/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
use Cake\Console\ConsoleOptionParser;
use Cake\Datasource\ConnectionManager;
use \App\Lib\Util\DeliveryUtilities;
use Cake\ORM\Locator\LocatorAwareTrait;

class TestCommand extends BaseCommand
{
use LocatorAwareTrait;

protected $io = null;

/**
Expand Down
3 changes: 3 additions & 0 deletions app/src/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\Locator\LocatorAwareTrait;

class UpgradeCommand extends BaseCommand
{
use LocatorAwareTrait;

protected $io = null;

// A list of known versions, must be semantic versioning compliant. The value
Expand Down
26 changes: 12 additions & 14 deletions app/src/Controller/ApiV2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ApiV2Controller extends AppController {
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\IndexQueryTrait;

protected string $tableName = '';

protected \Cake\ORM\Table $table;

/**
* Perform Cake Controller initialization.
*
Expand Down Expand Up @@ -82,9 +86,7 @@ public function add() {
/** var string $modelsName */
$modelsName = $this->getName();
/** var Cake\ORM\Table $table */
$table = $this->fetchTable($modelsName);
// $tableName = models
$tableName = $this->tableName;
$table = $this->getCurrentTable();

$json = $this->request->getData(); // Parsed by BodyParserMiddleware

Expand All @@ -97,13 +99,13 @@ public function add() {

foreach($json[$modelsName] as $rec) {
try {
$obj = $this->$modelsName->newEntity($rec);
$obj = $table->newEntity($rec);

if($this->$modelsName->saveOrFail($obj)) {
if($table->saveOrFail($obj)) {
$results[] = ['id' => $obj->id];

// Trigger provisioning, letting errors bubble up (AR-GMR-5)
if(method_exists($this->$modelsName, "requestProvisioning")) {
if(method_exists($table, "requestProvisioning")) {
$this->llog('rule', "AR-GMR-5 Requesting provisioning for $modelsName " . $obj->id);
$table->requestProvisioning(id: $obj->id, context: ProvisioningContextEnum::Automatic);
}
Expand Down Expand Up @@ -186,7 +188,7 @@ public function delete($id) {
/** var string $modelsName */
$modelsName = $this->getName();
/** var Cake\ORM\Table $table */
$table = $this->fetchTable($modelsName);
$table = $this->getCurrentTable();
// $tableName = models
$tableName = $table->getTable();

Expand Down Expand Up @@ -234,10 +236,8 @@ protected function dispatchIndex(string $mode = 'default') {
throw new UnauthorizedException(__d('error', 'perm'));
}

// $modelsName = Models
$modelsName = $this->getName();
/** var Cake\ORM\Table $table */
$table = $this->fetchTable($modelsName);
$table = $this->getCurrentTable();

$reqParameters = [...$this->request->getQuery()];
$pickerMode = ($mode === 'picker');
Expand Down Expand Up @@ -271,7 +271,7 @@ public function edit($id) {
/** var string $modelsName */
$modelsName = $this->getName();
/** var Cake\ORM\Table $table */
$table = $this->fetchTable($modelsName);
$table = $this->getCurrentTable();
// $tableName = models
$tableName = $table->getTable();

Expand Down Expand Up @@ -390,10 +390,8 @@ public function index() {
*/

public function view($id = null) {
/** var string $modelsName */
$modelsName = $this->getName();
/** var Cake\ORM\Table $table */
$table = $this->fetchTable($modelsName);
$table = $this->getCurrentTable();
// $tableName = models
$tableName = $table->getTable();

Expand Down
Loading

0 comments on commit 5861c82

Please sign in to comment.