Browse Source

Merge branch '4.x' into 4.next

ADmad 4 years ago
parent
commit
4ddb2d8a9e

+ 4 - 0
src/Cache/Engine/FileEngine.php

@@ -223,6 +223,10 @@ class FileEngine extends CacheEngine
         $path = $this->_File->getRealPath();
         $this->_File = null;
 
+        if ($path === false) {
+            return false;
+        }
+
         // phpcs:disable
         return @unlink($path);
         // phpcs:enable

+ 2 - 0
src/Controller/Controller.php

@@ -562,6 +562,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
      *  - `only`: (array|string) Only run the middleware for specified actions.
      *  - `except`: (array|string) Run the middleware for all actions except the specified ones.
      * @return void
+     * @since 4.3.0
      * @psalm-param array{only?: array|string, except?: array|string} $options
      */
     public function middleware($middleware, array $options = [])
@@ -576,6 +577,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
      * Get middleware to be applied for this controller.
      *
      * @return array
+     * @since 4.3.0
      */
     public function getMiddleware(): array
     {

+ 1 - 1
src/Core/PluginCollection.php

@@ -115,7 +115,7 @@ class PluginCollection implements Iterator, Countable
      * This method is not part of the official public API as plugins with
      * no plugin class are being phased out.
      *
-     * @param string $name The plugin name to locate a path for. Will return '' when a plugin cannot be found.
+     * @param string $name The plugin name to locate a path for.
      * @return string
      * @throws \Cake\Core\Exception\MissingPluginException when a plugin path cannot be resolved.
      * @internal

+ 20 - 19
src/ORM/Association/BelongsToMany.php

@@ -21,7 +21,6 @@ use Cake\Database\Expression\IdentifierExpression;
 use Cake\Database\Expression\QueryExpression;
 use Cake\Database\ExpressionInterface;
 use Cake\Datasource\EntityInterface;
-use Cake\Datasource\ResultSetInterface;
 use Cake\ORM\Association;
 use Cake\ORM\Association\Loader\SelectWithPivotLoader;
 use Cake\ORM\Query;
@@ -1188,27 +1187,29 @@ class BelongsToMany extends Association
 
                 $prefixedForeignKey = array_map([$junction, 'aliasField'], $foreignKey);
                 $junctionPrimaryKey = (array)$junction->getPrimaryKey();
-                $keys = array_combine($foreignKey, $prefixedForeignKey);
+                $junctionQueryAlias = $junction->getAlias() . '__matches';
+
+                $keys = $matchesConditions = [];
                 foreach (array_merge($assocForeignKey, $junctionPrimaryKey) as $key) {
-                    $keys[$key] = $junction->aliasField($key);
+                    $aliased = $junction->aliasField($key);
+                    $keys[$key] = $aliased;
+                    $matchesConditions[$aliased] = new IdentifierExpression($junctionQueryAlias . '.' . $key);
                 }
 
-                $existing = $this->_appendJunctionJoin($this->find())
-                    ->select($junction)
-                    ->where(array_combine($prefixedForeignKey, $primaryValue))
-                    ->formatResults(function (ResultSetInterface $results) use ($junction) {
-                        $junctionEntity = $junction->getEntityClass();
-                        $junctionAlias = $junction->getAlias();
-
-                        // Extract data for the junction entity and map the result
-                        // into junction entity instances so that delete callbacks work correctly.
-                        return $results->map(function ($item) use ($junctionEntity, $junctionAlias) {
-                            return new $junctionEntity(
-                                $item[$junctionAlias],
-                                ['markNew' => false, 'markClean' => true]
-                            );
-                        });
-                    });
+                // Use association to create row selection
+                // with finders & association conditions.
+                $matches = $this->_appendJunctionJoin($this->find())
+                    ->select($keys)
+                    ->where(array_combine($prefixedForeignKey, $primaryValue));
+
+                // Create a subquery join to ensure we get
+                // the correct entity passed to callbacks.
+                $existing = $junction->query()
+                    ->from([$junctionQueryAlias => $matches])
+                    ->innerJoin(
+                        [$junction->getAlias() => $junction->getTable()],
+                        $matchesConditions
+                    );
 
                 $jointEntities = $this->_collectJointEntities($sourceEntity, $targetEntities);
                 $inserts = $this->_diffLinks($existing, $jointEntities, $targetEntities, $options);