Skip to content

Commit

Permalink
cakephp5_upgrade_fixes (#335)
Browse files Browse the repository at this point in the history
* CAKEPHP5 upgrade fixes

* Review comments
  • Loading branch information
Ioannis authored Sep 13, 2025
1 parent b04aba0 commit cec8845
Show file tree
Hide file tree
Showing 47 changed files with 212 additions and 219 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
3 changes: 2 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,8 @@ public function initialize(array $config): void {
$this->setTableType(\App\Lib\Enum\TableTypeEnum::Configuration);

// Define associations
$this->belongsTo('Servers');
// XXX this is defined in HttpServersTable
// $this->belongsTo('Servers');
$this->hasMany('CoreServer.MatchServerAttributes')
->setDependent(true)
->setCascadeCallbacks(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function initialize(array $config): void {

// Define associations
// XXX this is defined in HttpServersTable
// $this->belongsTo('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
2 changes: 2 additions & 0 deletions app/src/Command/JobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

class JobCommand extends BaseCommand
{
use Cake\ORM\Locator\LocatorAwareTrait;

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

class NotificationCommand extends BaseCommand
{
use Cake\ORM\Locator\LocatorAwareTrait;

/**
* Register command specific options.
*
Expand Down Expand Up @@ -202,6 +205,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 +217,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
2 changes: 2 additions & 0 deletions app/src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

class SetupCommand extends BaseCommand
{
use Cake\ORM\Locator\LocatorAwareTrait;

/**
* Register command specific options.
*
Expand Down
2 changes: 2 additions & 0 deletions app/src/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

class TestCommand extends BaseCommand
{
use Cake\ORM\Locator\LocatorAwareTrait;

protected $io = null;

/**
Expand Down
2 changes: 2 additions & 0 deletions app/src/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

class UpgradeCommand extends BaseCommand
{
use Cake\ORM\Locator\LocatorAwareTrait;

protected $io = null;

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

protected string $tableName = '';

/**
* Perform Cake Controller initialization.
*
Expand All @@ -63,10 +65,8 @@ public function initialize(): void {
$this->setName($modelsName);
// Make this the default table for fetchTable()
$this->defaultTable = $modelsName;
// If you need a reusable handle for this request, keep it in a declared property
$this->table = $this->fetchTable();
// If you still need the table name as a property, assign it to a declared one
$this->tableName = $this->table->getTable();
$table = $this->fetchTable();
$this->tableName = $table->getTable();

// We want API auth, not Web Auth
$this->RegistryAuth->setConfig('apiUser', true);
Expand All @@ -82,9 +82,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 +95,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 +184,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 +232,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 +267,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 +386,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 cec8845

Please sign in to comment.