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

Remove __construct call from CustomerActiveCampaignAwareTrait #82

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions UPGRADE-0.X.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
# UPGRADE FROM `v0.1.0` TO `v0.X`

## UPGRADE FROM `v0.9.0` TO `v0.10.0`

> **BC** Method Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait#__construct() was removed

There was a bug due to a __construct method on the trait CustomerActiveCampaignAwareTrait. The constructor of the trait was never called. So that
the channelCustomers property was never initialized, or it was initialized to a null value. Even if it was a null value this was then used in a foreach, and it will trigger a deprecation error.
This bug has been fixed in this release. If you use the trait you can proceed in two ways:

1 - You can import the channelCustomersInitializers method and call it in the constructor of your entity. The result will be like this:
```php
<?php

namespace App\Entity\Customer;

use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Customer as BaseCustomer;
use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_customer")
*/
class Customer extends BaseCustomer implements CustomerActiveCampaignAwareInterface
{
use ActiveCampaignAwareTrait;
use CustomerActiveCampaignAwareTrait {
CustomerActiveCampaignAwareTrait::channelCustomersInitializers as private __channelCustomersInitializers;
}

public function __construct()
{
parent::__construct();
$this->__channelCustomersInitializers();
}
}
```

2 - If you prefer you can avoid to import the channelCustomersInitializers method and initialize yourself the
channelCustomers property in the constructor. The result will be like this:
```php
<?php

namespace App\Entity\Customer;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Customer as BaseCustomer;
use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_customer")
*/
class Customer extends BaseCustomer implements CustomerActiveCampaignAwareInterface
{
use ActiveCampaignAwareTrait;
use CustomerActiveCampaignAwareTrait;

public function __construct()
{
parent::__construct();
$this->channelCustomers = new ArrayCollection();
}
}
```

## UPGRADE FROM `v0.8.0` TO `v0.9.0`

Some services have been removed, please check if you are using them in your application and replace them:
Expand Down
40 changes: 40 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ nav_order: 2
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_customer")
*/
class Customer extends BaseCustomer implements CustomerActiveCampaignAwareInterface
{
use ActiveCampaignAwareTrait;
use CustomerActiveCampaignAwareTrait {
CustomerActiveCampaignAwareTrait::channelCustomersInitializers as private __channelCustomersInitializers;
}

public function __construct()
{
parent::__construct();
$this->__channelCustomersInitializers();
}
}
```

If you prefer you can avoid to import the channelCustomersInitializers method and initialize yourself the
channelCustomers property in the constructor. The result will be like this:

```php
<?php

namespace App\Entity\Customer;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Customer as BaseCustomer;
use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface;
use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_customer")
Expand All @@ -58,6 +92,12 @@ nav_order: 2
{
use ActiveCampaignAwareTrait;
use CustomerActiveCampaignAwareTrait;

public function __construct()
{
parent::__construct();
$this->channelCustomers = new ArrayCollection();
}
}
```

Expand Down
3 changes: 1 addition & 2 deletions src/Model/CustomerActiveCampaignAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\ChannelInterface;

trait CustomerActiveCampaignAwareTrait

Check failure on line 12 in src/Model/CustomerActiveCampaignAwareTrait.php

View workflow job for this annotation

GitHub Actions / Roave BC Check

Method Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait#__construct() was removed

Check failure on line 12 in src/Model/CustomerActiveCampaignAwareTrait.php

View workflow job for this annotation

GitHub Actions / Roave BC Check

Method Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait#__construct() was removed
{
/**
* @var Collection<ChannelCustomerInterface>|ChannelCustomerInterface[]
Expand All @@ -18,9 +18,8 @@
*/
protected $channelCustomers;

public function __construct()
private function channelCustomersInitializers(): void
{
parent::__construct();
$this->channelCustomers = new ArrayCollection();
}

Expand Down
10 changes: 9 additions & 1 deletion tests/Application/src/Entity/Customer/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,13 @@
class Customer extends BaseCustomer implements CustomerInterface
{
use ActiveCampaignAwareTrait;
use CustomerActiveCampaignAwareTrait;
use CustomerActiveCampaignAwareTrait {
CustomerActiveCampaignAwareTrait::channelCustomersInitializers as private __channelCustomersInitializers;
}

public function __construct()
{
parent::__construct();
$this->__channelCustomersInitializers();
}
}
Loading