Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setEntityId() to entityForm #16020

Merged
merged 1 commit into from
Mar 4, 2020

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Dec 3, 2019

Overview

Add a function to set the entity ID - we can already get it via getEntityID() but not set.

Before

No function to set entity ID on the form.

After

Function to set the entity ID on the form.

Technical Details

Comments

I'm looking at making some improvements / conversion to contributionview form and this is a pre-requisite to doing it properly.

@civibot
Copy link

civibot bot commented Dec 3, 2019

(Standard links)

@civibot civibot bot added the master label Dec 3, 2019
@seamuslee001
Copy link
Contributor

@mattwire test failure

ok 867 - CRM_Core_Page_AJAXTest::testCheckAuthz
PHP Fatal error:  CRM_Member_Form_MembershipConfig and CRM_Core_Form_EntityFormTrait define the same property ($_id) in the composition of CRM_Member_Form_MembershipType. However, the definition differs and is considered incompatible. Class was composed in /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php on line 23
PHP Stack trace:
PHP   1. {main}() /home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar:0
PHP   2. PHPUnit\TextUI\Command::main() /home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar:570
PHP   3. PHPUnit\TextUI\Command->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/TextUI/Command.php:148
PHP   4. PHPUnit\TextUI\TestRunner->doRun() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/TextUI/Command.php:195
PHP   5. PHPUnit\Framework\TestSuite->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/TextUI/TestRunner.php:545
PHP   6. PHPUnit\Framework\TestSuite->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestSuite.php:755
PHP   7. PHPUnit\Framework\TestSuite->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestSuite.php:755
PHP   8. CRM_Core_Page_HookTest->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestSuite.php:755
PHP   9. PHPUnit\Framework\TestResult->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestCase.php:894
PHP  10. CRM_Core_Page_HookTest->runBare() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestResult.php:698
PHP  11. CRM_Core_Page_HookTest->setUp() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestCase.php:935
PHP  12. is_subclass_of() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/Page/HookTest.php:59
PHP  13. spl_autoload_call() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/Page/HookTest.php:59
PHP  14. CRM_Core_ClassLoader->loadClass() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/Page/HookTest.php:59
PHP  15. require_once() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/CRM/Core/ClassLoader.php:211

Fatal error: CRM_Member_Form_MembershipConfig and CRM_Core_Form_EntityFormTrait define the same property ($_id) in the composition of CRM_Member_Form_MembershipType. However, the definition differs and is considered incompatible. Class was composed in /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php on line 23

Call Stack:
    0.0008     520528   1. {main}() /home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar:0
    0.0371    9395176   2. PHPUnit\TextUI\Command::main() /home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar:570
    0.0371    9403968   3. PHPUnit\TextUI\Command->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/TextUI/Command.php:148
    3.0942   93637184   4. PHPUnit\TextUI\TestRunner->doRun() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/TextUI/Command.php:195
    3.1215   93707464   5. PHPUnit\Framework\TestSuite->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/TextUI/TestRunner.php:545
  256.8721  162766984   6. PHPUnit\Framework\TestSuite->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestSuite.php:755
  359.3984  171715080   7. PHPUnit\Framework\TestSuite->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestSuite.php:755
  360.2296  167530888   8. CRM_Core_Page_HookTest->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestSuite.php:755
  360.2296  167530888   9. PHPUnit\Framework\TestResult->run() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestCase.php:894
  360.2297  167531728  10. CRM_Core_Page_HookTest->runBare() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestResult.php:698
  360.2297  167548192  11. CRM_Core_Page_HookTest->setUp() phar:///home/jenkins/bknix-dfl/civicrm-buildkit/extern/phpunit6/phpunit6.phar/phpunit/Framework/TestCase.php:935
  360.2964  178337880  12. is_subclass_of() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/Page/HookTest.php:59
  360.2964  178337936  13. spl_autoload_call() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/Page/HookTest.php:59
  360.2964  178338056  14. CRM_Core_ClassLoader->loadClass() /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/tests/phpunit/CRM/Core/Page/HookTest.php:59
  360.2967  178441360  15. require_once('/home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/CRM/Member/Form/MembershipType.php') /home/jenkins/bknix-dfl/build/core-16020-2rekg/web/sites/all/modules/civicrm/CRM/Core/ClassLoader.php:211

@mattwire
Copy link
Contributor Author

mattwire commented Feb 4, 2020

Hey @seamuslee001 is this failing because of the PropertyBag deprecated warnings?

@seamuslee001
Copy link
Contributor

@mattwire no

Fatal error: CRM_Member_Form and CRM_Core_Form_EntityFormTrait define the same property ($_id) in the composition of CRM_Member_Form. However, the definition differs and is considered incompatible. Class was composed in /home/jenkins/bknix-dfl/build/core-16020-5whfr/web/sites/all/modules/civicrm/CRM/Member/Form.php on line 22

@mattwire mattwire force-pushed the setentityid branch 4 times, most recently from e9f6567 to b1b2df1 Compare February 10, 2020 22:52
*
* @var int
*/
protected $_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire is there a reason why your making this protected rather than public?

@@ -28,7 +28,7 @@ class CRM_Member_Form_MembershipConfig extends CRM_Core_Form {
*
* @var int
*/
public $_id;
protected $_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire can you revert this change?

@mattwire mattwire force-pushed the setentityid branch 2 times, most recently from aede38b to c067823 Compare February 12, 2020 13:43
@seamuslee001
Copy link
Contributor

seamuslee001 commented Feb 12, 2020

@mattwire as your changing the visibility of $_id in CRM_Admin_Form then you need to make these changes as well

diff --git a/CRM/Admin/Form/Job.php b/CRM/Admin/Form/Job.php
index 8a8679b5b4..3009a5b730 100644
--- a/CRM/Admin/Form/Job.php
+++ b/CRM/Admin/Form/Job.php
@@ -19,7 +19,7 @@
  * Class for configuring jobs.
  */
 class CRM_Admin_Form_Job extends CRM_Admin_Form {
-  protected $_id = NULL;
+  public $_id = NULL;

   public function preProcess() {

diff --git a/CRM/Admin/Form/LabelFormats.php b/CRM/Admin/Form/LabelFormats.php
index 1713fd910b..9c60fe8de7 100644
--- a/CRM/Admin/Form/LabelFormats.php
+++ b/CRM/Admin/Form/LabelFormats.php
@@ -41,7 +41,7 @@ class CRM_Admin_Form_LabelFormats extends CRM_Admin_Form {
    * Label Format ID.
    * @var int
    */
-  protected $_id = NULL;
+  public $_id = NULL;

   /**
    * Group name, label format or name badge
diff --git a/CRM/Admin/Form/PaymentProcessorType.php b/CRM/Admin/Form/PaymentProcessorType.php
index 571aa957ac..89adf8ac7b 100644
--- a/CRM/Admin/Form/PaymentProcessorType.php
+++ b/CRM/Admin/Form/PaymentProcessorType.php
@@ -19,7 +19,7 @@
  * This class generates form components for Location Type.
  */
 class CRM_Admin_Form_PaymentProcessorType extends CRM_Admin_Form {
-  protected $_id = NULL;
+  public $_id = NULL;

   protected $_fields = NULL;

diff --git a/CRM/Admin/Form/PdfFormats.php b/CRM/Admin/Form/PdfFormats.php
index 8588c55516..0ec9042d58 100644
--- a/CRM/Admin/Form/PdfFormats.php
+++ b/CRM/Admin/Form/PdfFormats.php
@@ -41,7 +41,7 @@ class CRM_Admin_Form_PdfFormats extends CRM_Admin_Form {
    * PDF Page Format ID.
    * @var int
    */
-  protected $_id = NULL;
+  public $_id = NULL;

   /**
    * Build the form object.
diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php
index a845b5c644..e0fd77de3c 100644
--- a/CRM/Admin/Form/ScheduleReminders.php
+++ b/CRM/Admin/Form/ScheduleReminders.php
@@ -24,7 +24,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
    * Scheduled Reminder ID.
    * @var int
    */
-  protected $_id = NULL;
+  public $_id = NULL;

   public $_freqUnits;

@mattwire mattwire force-pushed the setentityid branch 2 times, most recently from 2bd7e0a to 9f92c58 Compare February 15, 2020 21:12
@seamuslee001
Copy link
Contributor

@mattwire same test is still failing CRM_Core_Page_AJAXTest::testFormsCallBuildFormOnce

@mattwire
Copy link
Contributor Author

@seamuslee001 Think we're finally there with this one!

@mattwire mattwire added the merge ready PR will be merged after a few days if there are no objections label Feb 25, 2020
@eileenmcnaughton
Copy link
Contributor

I'm just removing merge ready because that doesn't mean the way you are using it - it you give it to another person's Pr when you are ready to merge it but just want to give it few days cool off inn case someone else has a comment. Merge on pass is when you review another person's PR & it can be merged as soon as tests pass.

There are 2 things I'd want to check before merging this

  1. We should avoid making $id public if we can - we should aim for protected in general so we can better check what interacts with our code.
  2. sign setEntityId vs setEntityID() - I'll have to check but I feel we have been doing things the latter way increasingly

@eileenmcnaughton
Copy link
Contributor

Oh - the latter point -we have getEntityID & this adds setEntityId - I think it has to be caps then

@mattwire
Copy link
Contributor Author

mattwire commented Mar 4, 2020

We should avoid making $id public if we can - we should aim for protected in general so we can better check what interacts with our code.

Believe me I tried! Unfortunately the membership classes access the entity ID which (currently) require it to be public as they access the id property directly.

sign setEntityId vs setEntityID() - I'll have to check but I feel we have been doing things the latter way increasingly
Oh - the latter point -we have getEntityID & this adds setEntityId - I think it has to be caps then

I'm confused. We have getEntityId not getEntityID which is why I put it as setEntityId. I really don't mind which way though so please confirm which you'd prefer @eileenmcnaughton

@eileenmcnaughton
Copy link
Contributor

Ah - I based that on reading the PR not the code - PR comment is wrong it's entityId as you say.

OK - I'm happy to merge then

@eileenmcnaughton eileenmcnaughton merged commit b61b4be into civicrm:master Mar 4, 2020
@mattwire mattwire deleted the setentityid branch March 4, 2020 21:21
@mattwire
Copy link
Contributor Author

mattwire commented Mar 4, 2020

Thanks @eileenmcnaughton if I get chance I'll try and follow up sometime with some work on the membership classes to use this function and then we could probably switch back to a protected property.

@eileenmcnaughton
Copy link
Contributor

@mattwire yeah that would be good - they just need to call the sets & gets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants