Problem/Motivation
When I tried to import date column it gives :
Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\feeds\Feeds\Target\DateTargetBase->convertToDate() (line 26 of /modules/feeds/src/Feeds/Target/DateTargetBase.php)
#0 /core/includes/bootstrap.inc(347): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /modules/feeds/src/Feeds/Target/DateTargetBase.php(26): trim()
#3 /modules/feeds/src/Feeds/Target/DateTime.php(50): Drupal\feeds\Feeds\Target\DateTargetBase->convertToDate()
#4 /modules/feeds/src/Feeds/Target/DateTime.php(36): Drupal\feeds\Feeds\Target\DateTime->prepareDateValue()
#5 /modules/feeds/src/Plugin/Type/Target/FieldTargetBase.php(156): Drupal\feeds\Feeds\Target\DateTime->prepareValue()
#6 /modules/feeds/src/Plugin/Type/Target/FieldTargetBase.php(92): Drupal\feeds\Plugin\Type\Target\FieldTargetBase->prepareValues()
#7 /modules/feeds/src/Feeds/Processor/EntityProcessorBase.php(1092): Drupal\feeds\Plugin\Type\Target\FieldTargetBase->setTarget()
#8 /modules/feeds/src/Feeds/Processor/EntityProcessorBase.php(178): Drupal\feeds\Feeds\Processor\EntityProcessorBase->map()
#9 /modules/feeds/src/EventSubscriber/LazySubscriber.php(110): Drupal\feeds\Feeds\Processor\EntityProcessorBase->process()
#10 [internal function]: Drupal\feeds\EventSubscriber\LazySubscriber->Drupal\feeds\EventSubscriber\{closure}()
#11 /core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#12 /modules/feeds/src/Event/EventDispatcherTrait.php(38): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#13 /modules/feeds/src/FeedsExecutable.php(266): Drupal\feeds\FeedsExecutable->dispatchEvent()
#14 /modules/feeds/src/FeedsExecutable.php(113): Drupal\feeds\FeedsExecutable->doProcess()
#15 /core/includes/batch.inc(295): Drupal\feeds\FeedsExecutable->processItem()
#16 /core/includes/batch.inc(137): _batch_process()
#17 /core/includes/batch.inc(93): _batch_do()
#18 /core/modules/system/src/Controller/BatchController.php(55): _batch_page()
#19 [internal function]: Drupal\system\Controller\BatchController->batchPage()
#20 /core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#21 /core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 /core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#23 /core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#24 /vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#25 /vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#26 /core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#27 /core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#28 /core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#29 /core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#30 /core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#31 /core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#32 /vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#33 /core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle()
#34 /index.php(19): Drupal\Core\DrupalKernel->handle()
#35 {main}
-------- This issue is very similar to already reported one :"https://www.drupal.org/project/feeds/issues/3267244" However I cannot fix it ,so anyone can help to resolve that issue after upgrading to PHP 8.1.14
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | data._csv.txt | 16 bytes | megachriz |
| #15 | feeds.feed_type.csv_.yml_.txt | 1.1 KB | megachriz |
Issue fork feeds-3306211
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
coaston commentedComment #3
coaston commentedOk it seems I was successful :
* @return \Drupal\Core\Datetime\DrupalDateTime|null
* A datetime object or null, if there is no value or if the date value
* has errors.
*/
protected function convertToDate($value) {
- $value = trim($value);
+ $value = trim($value ?? '');
This change on (line 26 of /modules/feeds/src/Feeds/Target/DateTargetBase.php) fixed the issue. Anyone can double check and provide the patch ?
Comment #4
coaston commentedComment #5
megachrizIt would be good if this bug is covered by an automated test.
Can you provide the config file from your feed type + the source file you were trying to import?
You can export your configuration this way:
Comment #6
VenkatK commentedDeprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\feeds\Feeds\Target\Boolean->prepareValue() (line 24 modules/contrib/feeds/src/Feeds/Target/Boolean.php)
We have similar issue in Boolean.php
Comment #7
megachriz@VenkatK
Alright, please share the source file and your feed type configuration. This way we can write an automated test for the bug.
Comment #8
coaston commentedHi MegaChriz, will provide the config later next week due to vacation, but it seems it happens when there is date field in feeds but this column is missing in csv.
Example :
Feed config has 3 fields :
Title,
Date1
Date2
and this reported issue occures when you create csv with just 2 columns Title and Date1....so Date2 is missing and instead of ignoring it ,it will throw such error. However it seems this works fine when there is any other field type and it will just ignore such missing column with string for example.
But I will confirm next week.
Comment #9
solideogloria commentedFYI: The null-coalesce operator
??was introduced in PHP 7.0, so if you use that, you need to addphp = 7.0as a minimum version requirement in the feeds.info file.Comment #10
coaston commentedHi solideaoglori
My Php version is 8.1.4
Comment #13
lind101 commentedThere are a few places in the FieldTarget classes where trim and strlen function are being use without checking for the existance of a string value. This will create warning for people using PHP 8 or higher.
MR!90 is a first pass at suppressing these warnings for PHP 8 users and still making sure the module works for users running older versions of PHP.
Updated the issue title to include refernce to PHP 8.
Comment #14
coaston commentedHi All,
I can confirm above merge #13 worked for me and resolved my reported issues, hence this can be closed and added to new release.
Comment #15
megachrizIt would still be useful to have automated tests for this.
I was able to reproduce the issue when mapping to a date field. I've attached a feed type to reproduce the issue with. And a CSV file.
Comment #18
megachrizMerged the code. Thanks all!