[FEATURE] Replace @cascade with @Extbase\ORM\Cascade 61/54761/4
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Sat, 25 Nov 2017 13:57:05 +0000 (14:57 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 27 Nov 2017 16:12:04 +0000 (17:12 +0100)
This patch introduces the "TYPO3\CMS\Extbase\Annotation\ORM\Cascade"
annotation that replaces the @cascade annotation which is
deprecated from now on.

Releases: master
Resolves: #83093
Change-Id: I1637d69b8bed0cdf85c009b43c3afd45ee7d29ff
Reviewed-on: https://review.typo3.org/54761
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Annotation/ORM/Cascade.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Reflection/ClassSchema.php
typo3/sysext/extbase/Tests/Unit/Reflection/Fixture/DummyClassWithAllTypesOfProperties.php
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/ClassSchemaTest.php
typo3/sysext/extbase/Tests/UnitDeprecated/Reflection/Fixture/DummyClassWithAllTypesOfProperties.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst
new file mode 100644 (file)
index 0000000..9bc97ec
--- /dev/null
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=====================================================================================
+Deprecation: #83093 - Replace @cascade with @TYPO3\CMS\Extbase\Annotation\ORM\Cascade
+=====================================================================================
+
+See :issue:`83093`
+
+Description
+===========
+
+The `@cascade` annotation has been deprecated and must be replaced with the doctrine annotation `@TYPO3\CMS\Extbase\Annotation\ORM\Cascade`.
+
+
+Impact
+======
+
+From version 9.0 on, `@cascade` is deprecated and will be removed in version 10.
+
+
+Affected Installations
+======================
+
+All extensions that use `@cascade`
+
+
+Migration
+=========
+
+Use `@TYPO3\CMS\Extbase\Annotation\ORM\Cascade` instead.
+
+A tyical example has been `@cascade remove` which is now `@TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")`
+
+.. index:: PHP-API, ext:extbase, FullyScanned
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst
new file mode 100644 (file)
index 0000000..30cfb09
--- /dev/null
@@ -0,0 +1,59 @@
+.. include:: ../../Includes.txt
+
+=================================================================================
+Feature: #83093 - Replace @cascade with @TYPO3\CMS\Extbase\Annotation\ORM\Cascade
+=================================================================================
+
+See :issue:`83093`
+
+Description
+===========
+
+As a successor to the `@cascade` annotation, the doctrine annotation `@TYPO3\CMS\Extbase\Annotation\ORM\Cascade` has been introduced.
+
+Example:
+
+.. code-block:: php
+
+       /**
+        * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
+        */
+       public $property;
+
+Doctrine annotations are actual defined classes, therefore you can also use the annotation with a use statement.
+
+Example:
+
+.. code-block:: php
+
+       use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
+
+.. code-block:: php
+
+       /**
+        * @Cascade("remove")
+        */
+       public $property;
+
+Used annotations can also be aliased which the core will most likely be using a lot in the future.
+
+Example:
+
+.. code-block:: php
+
+       use TYPO3\CMS\Extbase\Annotation as Extbase;
+
+.. code-block:: php
+
+       /**
+        * @Extbase\ORM\Cascade("remove")
+        */
+       public $property;
+
+
+Impact
+======
+
+In 9.x there is no actual impact. Both the simple `@cascade` and `@TYPO3\CMS\Extbase\Annotation\ORM\Cascade` can be used side by side. However, `@cascade` is deprecated in 9.x and will be removed in version 10.
+
+.. index:: PHP-API, ext:extbase, FullyScanned
diff --git a/typo3/sysext/extbase/Classes/Annotation/ORM/Cascade.php b/typo3/sysext/extbase/Classes/Annotation/ORM/Cascade.php
new file mode 100644 (file)
index 0000000..624f401
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+declare(strict_types=1);
+
+namespace TYPO3\CMS\Extbase\Annotation\ORM;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * @Annotation
+ * @Target({"PROPERTY"})
+ */
+class Cascade
+{
+    /**
+     * @Enum({"remove"})
+     *
+     * Currently, Extbase does only support "remove".
+     *
+     * Other possible cascade operations would be: "persist", "merge", "detach", "refresh", "all"
+     * @see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations
+     */
+    public $value;
+
+    /**
+     * @param array $values
+     */
+    public function __construct(array $values)
+    {
+        if (isset($values['value'])) {
+            $this->value = $values['value'];
+        }
+    }
+}
index 00e488a..8082e89 100644 (file)
@@ -18,6 +18,7 @@ use Doctrine\Common\Annotations\AnnotationReader;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\ClassNamingUtility;
 use TYPO3\CMS\Extbase\Annotation\Inject;
+use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
 use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
 use TYPO3\CMS\Extbase\Annotation\ORM\Transient;
 use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
@@ -246,6 +247,18 @@ class ClassSchema
                 } catch (\Exception $e) {
                 }
 
+                if ($this->properties[$propertyName]['annotations']['cascade'] !== null) {
+                    trigger_error(
+                        'Tagging properties with @cascade is deprecated and will be removed in TYPO3 v10.0.',
+                        E_USER_DEPRECATED
+                    );
+                }
+
+                if (($annotation = $annotationReader->getPropertyAnnotation($reflectionProperty, Cascade::class)) instanceof Cascade) {
+                    /** @var Cascade $annotation */
+                    $this->properties[$propertyName]['annotations']['cascade'] = $annotation->value;
+                }
+
                 try {
                     $type = TypeHandlingUtility::parseType(implode(' ', $docCommentParser->getTagValues('var')));
                 } catch (\Exception $e) {
index e4fad39..459e197 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture;
  */
 
 use TYPO3\CMS\Extbase\Annotation\Inject;
+use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
 use TYPO3\CMS\Extbase\Annotation\ORM\Transient;
 
 /**
@@ -57,12 +58,12 @@ class DummyClassWithAllTypesOfProperties
 
     /**
      * @var DummyClassWithAllTypesOfProperties
-     * @cascade remove
+     * @Cascade("remove")
      */
     public $propertyWithCascadeAnnotation;
 
     /**
-     * @cascade remove
+     * @Cascade("remove")
      */
     public $propertyWithCascadeAnnotationWithoutVarAnnotation;
 
index 85bacb2..84fc91e 100644 (file)
@@ -38,4 +38,20 @@ class ClassSchemaTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $classSchema = new ClassSchema(Fixture\DummyClassWithLazyProperty::class);
         static::assertTrue($classSchema->getProperty('propertyWithLazyAnnotation')['annotations']['lazy']);
     }
+
+    public function testClassSchemaDetectsCascadeProperty()
+    {
+        $classSchema = new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
+
+        $propertyDefinition = $classSchema->getProperty('propertyWithCascadeAnnotation');
+        static::assertSame('remove', $propertyDefinition['annotations']['cascade']);
+    }
+
+    public function testClassSchemaDetectsCascadePropertyOnlyWithVarAnnotation()
+    {
+        $classSchema = new ClassSchema(Fixture\DummyClassWithAllTypesOfProperties::class);
+
+        $propertyDefinition = $classSchema->getProperty('propertyWithCascadeAnnotationWithoutVarAnnotation');
+        static::assertNull($propertyDefinition['annotations']['cascade']);
+    }
 }
index 1ef9b31..c6a37e7 100644 (file)
@@ -27,4 +27,15 @@ class DummyClassWithAllTypesOfProperties
      * @transient
      */
     public $propertyWithTransientAnnotation;
+
+    /**
+     * @var DummyClassWithAllTypesOfProperties
+     * @cascade remove
+     */
+    public $propertyWithCascadeAnnotation;
+
+    /**
+     * @cascade remove
+     */
+    public $propertyWithCascadeAnnotationWithoutVarAnnotation;
 }
index 2eebc79..947c247 100644 (file)
@@ -18,4 +18,10 @@ return [
             'Deprecation-83092-ReplaceTransientWithTYPO3CMSExtbaseAnnotationORMTransient.rst',
         ],
     ],
+    '@cascade' => [
+        'restFiles' => [
+            'Feature-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst',
+            'Deprecation-83093-ReplaceCascadeWithTYPO3CMSExtbaseAnnotationORMCascade.rst',
+        ],
+    ],
 ];