Skip to content

CAKEPHP upgrade to 5.2.7 #334

Merged
merged 1 commit into from
Sep 11, 2025
Merged

Conversation

Ioannis
Copy link
Contributor

@Ioannis Ioannis commented Sep 9, 2025

Important changes:

  • ORM: order to orderBy,

example:

- ->order(['EnrollmentFlowSteps.ordr' => 'ASC'])
+ ->orderBy(['EnrollmentFlowSteps.ordr' => 'ASC'])
  • ORM: get() now uses named parameters instead of positional

example:

- $linkObj = $linkTable->get($link->value, ['contain' => $contain]);
+ $linkObj = $linkTable->get($link->value, contain: $contain);

A more complex example:

-    $query = $Types->find('list', [
-                           'keyField'    => 'value',
-                            'valueField'  => 'display_name'
-                          ])
+    $query = $Types->find('list',
+                           keyField:  'value',
+                          valueField: 'display_name',
+                          )
                   ->where(['co_id'     => $coId,
                            'attribute' => $attribute,
                            'status'    => SuspendableStatusEnum::Active])
-                   ->order(['Types.display_name' => 'ASC']);
+                   ->orderBy(['Types.display_name' => 'ASC']);
  • Returning values from event listeners / callbacks is deprecated. Use $event->setResult() instead or $event->stopPropogation() to just stop the event propagation.

example:

if($controller->calculatePermission()) {
-   return true;
+   $event->setResult(true);
+   return;
}
  • pagination results need to be called through items

example:

-  while($rs->valid()) {
-   $o = $rs->current();
+ while($rs->items()->valid()) {
+   $o = $rs->items()->current();
  • Fix the Dynamic Properties issue. This warning/error has been introduced in php 8.2+ version. We should no longer do $modelsName = $this->name. Instead it is recommended to use the object methods. The same for the $table object. We need to use the fetchTable method. This way we eliminate the dynamic property issue

example:

/** var string $modelsName */
- $modelsName = $this->name;
+ $modelsName = $this->getName();
/** var Cake\ORM\Table $table */
- $table = $this->$modelsName;
+ $table = $this->fetchTable($modelsName);
⚠️ WARNING
For the dynamic attributes we need to eliminate the usage of $this->$modelsName all around the application.
  • When we load components we need to use the $this->components() object to make all the handling. Nevertheless the magic _get method will return the component itself in the $this->RegistryAuth if we need to access it directly. This is not working properly when we try to use the isset($this->RegistryAuth)

example:

// COmanage components
- isset($this->RegistryAuth)
+ $this->components()->has('RegistryAuth')

@Ioannis Ioannis requested review from benno and arlen September 9, 2025 15:04
@Ioannis Ioannis force-pushed the cakephp5_upgrade branch 6 times, most recently from ff996fe to 8953ff2 Compare September 10, 2025 14:06
Fix DynamicProperties php 8.2 issue

Sync configuration files
@benno benno merged commit 5493369 into COmanage:develop Sep 11, 2025
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants