magento / magento/data-migration-tool
Migration\Handler\SetValue not compatible with PHP 8.1
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 339
- Forks
- 195
- PR merge metrics
- No merged PRs in 30d
Description
### Preconditions
1. Magento 1 with tier prices
2. Migration to Magento 2.4.5 (opensource to opensource)
3. PHP 8.1
### Steps to reproduce
1. Migrate Magento 1 to Magento 2
### Expected result
1. Migration completes successfully
### Actual result
Error in the OrderGrids Step:
```
[2022-12-05T08:22:49.790153+00:00][DEBUG][mode: data][stage: data migration][step: Tier Price Step][table: catalog_product_entity_tier_price]: migrating
0% [>---------------------------] Remaining Time: < 1 sec
In ErrorHandler.php line 62:
[Exception]
Deprecated Functionality: substr(): Passing null to parameter #1 ($string)
of type string is deprecated in /var/www/html/magento/vendor/magento/data-m
igration-tool/src/Migration/Handler/SetValue.php on line 35
Exception trace:
at /var/www/html/magento/vendor/magento/framework/App/ErrorHandler.php:62
Magento\Framework\App\ErrorHandler->handler() at n/a:n/a
substr() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/Handler/SetValue.php:35
Migration\Handler\SetValue->handle() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/RecordTransformer.php:126
Migration\RecordTransformer->applyHandlers() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/RecordTransformer.php:74
Migration\RecordTransformer->transform() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/Step/TierPrice/Data.php:139
Migration\Step\TierPrice\Data->perform() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/Mode/AbstractMode.php:82
Migration\Mode\AbstractMode->runStage() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/Mode/Data.php:124
Migration\Mode\Data->runData() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/Mode/Data.php:69
Migration\Mode\Data->run() at /var/www/html/magento/vendor/magento/data-migration-tool/src/Migration/Console/MigrateDataCommand.php:59
Migration\Console\MigrateDataCommand->execute() at /var/www/html/magento/vendor/symfony/console/Command/Command.php:255
Symfony\Component\Console\Command\Command->run() at /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php:58
Migration\Console\MigrateDataCommand\Interceptor->___callParent() at /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php:138
Migration\Console\MigrateDataCommand\Interceptor->Magento\Framework\Interception\{closure}() at /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php:153
Migration\Console\MigrateDataCommand\Interceptor->___callPlugins() at /var/www/html/magento/generated/code/Migration/Console/MigrateDataCommand/Interceptor.php:77
Migration\Console\MigrateDataCommand\Interceptor->run() at /var/www/html/magento/vendor/symfony/console/Application.php:1021
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/magento/vendor/symfony/console/Application.php:275
Symfony\Component\Console\Application->doRun() at /var/www/html/magento/vendor/magento/framework/Console/Cli.php:116
Magento\Framework\Console\Cli->doRun() at /var/www/html/magento/vendor/symfony/console/Application.php:149
Symfony\Component\Console\Application->run() at /var/www/html/magento/bin/magento:23
```
### Additional notes
The problem is triggered by the `map-tier-price.xml.dist` configuration
```xml
catalog_product_entity_group_price.value_id
catalog_product_entity_tier_price.value_id
```
because the `Migration\Handler\SetValue` class throws an error if NULL should be set:
```php
value = (strtoupper($value) === 'NULL') ? null : $value;
}
/**
* @inheritdoc
*/
public function handle(Record $recordToHandle, Record $oppositeRecord)
{
$this->validate($recordToHandle);
$valueStored = $recordToHandle->getValue($this->field);
$operator = substr($this->value, 0, 1);
$value = substr($this->value, 1);
switch ($operator) {
case '+':
$value = $valueStored + $value;
break;
case '-';
$value = $valueStored - $value;
break;
default:
$value = $this->value;
}
$recordToHandle->setValue($this->field, $value);
}
}
```
The problem are the lines
```php
$operator = substr($this->value, 0, 1);
$value = substr($this->value, 1);
```
if `$this->value` is null, since null musn't be used anymore in `substr`.
As a workaround I changed the lines to
```php
$operator = substr($this->value ?? '', 0, 1);
$value = substr($this->value ?? '', 1);
```
and could finish the migration.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/Migration/Handler/SetValue.php, especially handle() and the substr() calls, then review the map-tier-price.xml.dist configuration that passes NULL. Reproduce the Magento 1 to Magento 2.4.5 migration with PHP 8.1 and verify that the Tier Price step completes without the deprecation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100