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

[4.x]: Rebuilding project config throws an Invalid condition class becasue of removed plugins #12881

Closed
vnali opened this issue Mar 13, 2023 · 10 comments
Assignees

Comments

@vnali
Copy link
Contributor

vnali commented Mar 13, 2023

What happened?

Description

After removing a plugin, i can see some configs of that plugin remains in project config. Also rebuilding the project config, throws an error because of those configs. For example:
removing craft commerce and rebuilding project config throws :
Invalid condition class: craft\commerce\elements\conditions\orders\OrderCondition
i can see these lines on loaded project config even after removing the commerce plugin

elementSources:
  craft\commerce\elements\Order:
    -
      defaultSort:
        - dateOrdered
        - desc
      disabled: false
      key: '*'
      tableAttributes:
        - reference
        - orderStatus
        - dateOrdered
        - datePaid
        - totalPaid
        - paidStatus
        - totals
      type: native
    -
      heading: 'Order Status'
      type: heading
    -
      key: 'orderStatus:new'
      type: native
    -
      heading: Carts
      type: heading
    -
      key: 'carts:active'
      type: native
    -
      key: 'carts:inactive'
      type: native
    -
      key: 'carts:attempted-payment'
      type: native
    -
      condition:
        **class: craft\commerce\elements\conditions\orders\OrderCondition**
        conditionRules:
          -
            class: craft\elements\conditions\RelatedToConditionRule
            elementId: $CONTENT_LENGTH
            elementType: craft\elements\Entry
            uid: 778731d0-111f-46a2-bed1-84682839e8cf
        elementType: craft\commerce\elements\Order
        fieldContext: global
      defaultSort:
        - number
        - asc
      key: 'custom:b4ffa510-5a7c-4609-9a90-5c133520f9b5'
      label: order1
      tableAttributes: '-'
      type: custom
    -
      condition:
        **class: craft\commerce\elements\conditions\orders\OrderCondition**
        conditionRules:
          -
            class: craft\commerce\elements\conditions\orders\CustomerConditionRule
            operator: in
            uid: a8d2ee49-4fd6-4e26-8a3d-33f0a0d67900
            values:
              - '1'
        elementType: craft\commerce\elements\Order
        fieldContext: global
      defaultSort:
        - number
        - asc
      key: 'custom:d3edc11a-61a0-4586-9362-18b9a5b94a7f'
      label: order2
      tableAttributes: '-'
      type: custom

Craft CMS version

4.3.11

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for reporting that! Fixed for the next release.

@vnali
Copy link
Contributor Author

vnali commented Mar 14, 2023

@brandonkelly i tried to test it with the fix. now i have problem with another removed plugin and its config:

Class "putyourlightson\campaign\elements\CampaignElement" not found
i had this in loaded config related to the Campaign:

  putyourlightson\campaign\elements\CampaignElement:
    -
      defaultSort:
        - lastSent
        - desc
      disabled: true
      key: '*'
      tableAttributes:
        - campaignType
        - recipients
        - opened
        - clicked
        - link
      type: native
    -
      heading: ''
      type: heading
    -
      condition:
        class: craft\elements\conditions\ElementCondition
        conditionRules:
          -
            class: craft\elements\conditions\RelatedToConditionRule
            elementId: $CONTENT_LENGTH
            elementType: craft\elements\Entry
            uid: a04da9e3-06d1-4145-a196-880ecdb4f02b
        elementType: putyourlightson\campaign\elements\CampaignElement
        fieldContext: global
      defaultSort:
        - title
        - asc
      key: 'custom:a370f0ea-42af-45dc-8839-8db37661c43e'
      label: test
      tableAttributes: '-'
      type: custom
  putyourlightson\campaign\elements\ContactElement:
    -
      defaultSort:
        - title
        - asc
      disabled: true
      key: '*'
      tableAttributes:
        - country
        - lastActivity
      type: native

and stacktrace is:

Error: Class "putyourlightson\campaign\elements\CampaignElement" not found in /var/www/html/craft4test/vendor/craftcms/cms/src/elements/conditions/ElementCondition.php:115
Stack trace:

#0 /var/www/html/craft4test/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(112): craft\elements\conditions\ElementCondition->conditionRuleTypes()
#1 /var/www/html/craft4test/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(231): craft\base\conditions\BaseCondition->getConditionRuleTypes()
#2 /var/www/html/craft4test/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(199): craft\base\conditions\BaseCondition->validateConditionRule()
#3 [internal function]: craft\base\conditions\BaseCondition->craft\base\conditions\{closure}()
#4 /var/www/html/craft4test/vendor/illuminate/collections/Arr.php(830): array_filter()
#5 /var/www/html/craft4test/vendor/illuminate/collections/Collection.php(382): Illuminate\Support\Arr::where()
#6 /var/www/html/craft4test/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(199): Illuminate\Support\Collection->filter()
#7 /var/www/html/craft4test/vendor/yiisoft/yii2/base/Component.php(180): craft\base\conditions\BaseCondition->setConditionRules()
#8 /var/www/html/craft4test/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set()
#9 /var/www/html/craft4test/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure()
#10 /var/www/html/craft4test/vendor/craftcms/cms/src/base/Model.php(78): yii\base\BaseObject->__construct()
#11 /var/www/html/craft4test/vendor/craftcms/cms/src/elements/conditions/ElementCondition.php(59): craft\base\Model->__construct()
#12 [internal function]: craft\elements\conditions\ElementCondition->__construct()
#13 /var/www/html/craft4test/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs()
#14 /var/www/html/craft4test/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build()
#15 /var/www/html/craft4test/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get()
#16 /var/www/html/craft4test/vendor/craftcms/cms/src/Craft.php(53): yii\BaseYii::createObject()
#17 /var/www/html/craft4test/vendor/craftcms/cms/src/services/Conditions.php(69): Craft::createObject()
#18 /var/www/html/craft4test/vendor/craftcms/cms/src/services/ProjectConfig.php(1871): craft\services\Conditions->createCondition()
#19 /var/www/html/craft4test/vendor/craftcms/cms/src/services/ProjectConfig.php(1175): craft\services\ProjectConfig->_getElementSourceData()
#20 /var/www/html/craft4test/vendor/craftcms/cms/src/controllers/ProjectConfigController.php(90): craft\services\ProjectConfig->rebuild()
#21 [internal function]: craft\controllers\ProjectConfigController->actionRebuild()
#22 /var/www/html/craft4test/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#23 /var/www/html/craft4test/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#24 /var/www/html/craft4test/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#25 /var/www/html/craft4test/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction()
#26 /var/www/html/craft4test/vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction()
#27 /var/www/html/craft4test/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest()
#28 /var/www/html/craft4test/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#29 /var/www/html/craft4test/web/index.php(12): yii\base\Application->run()
#30 {main}

brandonkelly added a commit that referenced this issue Mar 14, 2023
brandonkelly added a commit that referenced this issue Mar 14, 2023
@brandonkelly
Copy link
Member

@vnali That should be fully fixed in 4.4.2.

@vnali
Copy link
Contributor Author

vnali commented Mar 15, 2023

Sorry to bother you @brandonkelly, the error Class "putyourlightson\campaign\elements\CampaignElement" not found still persists on 4.4.2
i tried to trace it and i think on error ElementCondition object is created on Conditions service like:

class:
"craft\elements\conditions\ElementCondition"
atrributes:
array:2 [▼
  "elementType" => "putyourlightson\campaign\elements\CampaignElement"
  "fieldContext" => "global"
]
conditionRules:
array:1 [▼
  0 => array:4 [▼
    "class" => "craft\elements\conditions\RelatedToConditionRule"
    "elementId" => "$CONTENT_LENGTH"
    "elementType" => "craft\elements\Entry"
    "uid" => "a04da9e3-06d1-4145-a196-880ecdb4f02b"
  ]
]

received on elementCondition _construct() and elementType is null so InvalidConfigException is not catched maybe? and parameters are like this:

$elementType: null
$config: // as json encoded
{"attributes":{"elementType":"putyourlightson\\campaign\\elements\\CampaignElement","fieldContext":"global"},"conditionRules":[{"class":"craft\\elements\\conditions\\RelatedToConditionRule","elementId":"$CONTENT_LENGTH","elementType":"craft\\elements\\Entry","uid":"a04da9e3-06d1-4145-a196-880ecdb4f02b"}]}

@brandonkelly
Copy link
Member

Doh… fixed it for cases where the $elementType arg was set, but not for when it was part of the $config array. That is fixed as well now!

@brandonkelly
Copy link
Member

4.4.3 is out with that fix.

@vnali
Copy link
Contributor Author

vnali commented Mar 16, 2023

@brandonkelly I just tested 4.4.3 and had same problem . i 'm not sure if it is proper fix but replaced ArrayHelper::remove($config, 'elementType') with ArrayHelper::remove($config['attributes'], 'elementType') to get element type and i was able to rebuild project config

brandonkelly added a commit that referenced this issue Mar 16, 2023
Forgot it could be in $config['attributes']
@brandonkelly
Copy link
Member

@vnali Thanks! Updated for that possibility as well.

@vnali
Copy link
Contributor Author

vnali commented Mar 16, 2023

Thanks @brandonkelly with the latest fix i'm able to rebuild the project config

@brandonkelly
Copy link
Member

Craft 4.4.4 is out now with that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants