[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Profiles Trackers: prevent ItemsList array_map fatal in Wildcard_items profile apply
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a96c6b676b0a_3818e78c99658@gitlab-sidekiq-low-urgency-cpu-bound-v2-77f8664f6c-gnrm4.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
88e19051 by MAGENE Sem Joel at 2026-09-01T12:20:33+00:00
[FIX] Profiles Trackers: prevent ItemsList array_map fatal in Wildcard_items profile apply
---
* [FIX] Profiles Trackers: prevent ItemsList array_map fatal in Wildcard_items profile apply
See merge request tikiwiki/tiki!10240
- - - - -
2 changed files:
- lib/core/Tiki/Profile/InstallHandler/TrackerItem.php
- + lib/test/Core/Tiki/Profile/TrackerItemInstallHandlerTest.php
Changes:
=====================================
lib/core/Tiki/Profile/InstallHandler/TrackerItem.php
=====================================
@@ -108,6 +108,15 @@ class Tiki_Profile_InstallHandler_TrackerItem extends Tiki_Profile_InstallHandle
}
}
+ // ItemsList stores linked item IDs. Rendered display values from profiles
+ // cannot be restored here without resolving them, so only already-resolved
+ // ID arrays are passed to replace_item().
+ foreach ($fields['data'] as $key => $entry) {
+ if (($entry['type'] ?? '') === 'l' && ! is_array($entry['value'] ?? null)) {
+ unset($fields['data'][$key]);
+ }
+ }
+
if ($this->mode == 'update') {
foreach ($fields['data'] as $key => $entry) {
if (! in_array($entry['fieldId'], $providedfields)) {
=====================================
lib/test/Core/Tiki/Profile/TrackerItemInstallHandlerTest.php
=====================================
@@ -0,0 +1,146 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+namespace Tiki\Lib\Test\Core\Tiki\Profile;
+
+use TikiLib;
+use Tiki_Profile_InstallHandler_TrackerItem;
+use Tiki_Profile_Object;
+use TestableTikiLib;
+use TikiTestCase;
+
+class TrackerItemInstallHandlerTest extends TikiTestCase
+{
+ private $overrideLibs;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $this->overrideLibs = new TestableTikiLib();
+ }
+
+ protected function tearDown(): void
+ {
+ $this->overrideLibs = null;
+ parent::tearDown();
+ }
+
+ /**
+ * @dataProvider invalidItemsListValues
+ */
+ public function testDoInstallSkipsInvalidItemsListValue(array $values): void
+ {
+ $trklib = $this->createMock(get_class(TikiLib::lib('trk')));
+ $trklib->expects($this->once())
+ ->method('list_tracker_fields')
+ ->with(1)
+ ->willReturn([
+ 'data' => [
+ ['fieldId' => 10, 'permName' => 'items_field', 'type' => 'l'],
+ ['fieldId' => 11, 'permName' => 'title', 'type' => 't'],
+ ],
+ ]);
+ $trklib->expects($this->once())
+ ->method('replace_item')
+ ->with(
+ 1,
+ 0,
+ $this->callback(function (array $fields): bool {
+ $fieldsById = array_column($fields['data'], null, 'fieldId');
+ $this->assertArrayNotHasKey(10, $fieldsById);
+ $this->assertSame('Task 1', $fieldsById[11]['value']);
+ return true;
+ }),
+ 'o'
+ )
+ ->willReturn(123);
+
+ $this->overrideLibs->overrideLibs(['trk' => $trklib]);
+
+ $object = $this->getMockBuilder(Tiki_Profile_Object::class)
+ ->disableOriginalConstructor()
+ ->onlyMethods(['getData'])
+ ->getMock();
+ $object->method('getData')->willReturn([
+ 'tracker' => 1,
+ 'status' => 'open',
+ 'values' => $values,
+ ]);
+
+ $handler = new class ($object, false) extends Tiki_Profile_InstallHandler_TrackerItem {
+ public function replaceReferences(mixed &$data): void
+ {
+ }
+ };
+
+ $this->assertSame(123, $handler->doInstall());
+ }
+
+ public static function invalidItemsListValues(): array
+ {
+ return [
+ 'rendered value' => [
+ [
+ ['items_field', 'tm2'],
+ ['title', 'Task 1'],
+ ],
+ ],
+ 'omitted value' => [
+ [
+ ['title', 'Task 1'],
+ ],
+ ],
+ ];
+ }
+
+ public function testDoInstallPassesItemIdsForItemsListField(): void
+ {
+ $trklib = $this->createMock(get_class(TikiLib::lib('trk')));
+ $trklib->expects($this->once())
+ ->method('list_tracker_fields')
+ ->with(1)
+ ->willReturn([
+ 'data' => [
+ ['fieldId' => 10, 'permName' => 'items_field', 'type' => 'l'],
+ ],
+ ]);
+ $trklib->expects($this->once())
+ ->method('replace_item')
+ ->with(
+ 1,
+ 0,
+ $this->callback(function (array $fields): bool {
+ $this->assertSame([12, 34], $fields['data'][0]['value']);
+ return true;
+ }),
+ 'o'
+ )
+ ->willReturn(123);
+
+ $this->overrideLibs->overrideLibs(['trk' => $trklib]);
+
+ $object = $this->getMockBuilder(Tiki_Profile_Object::class)
+ ->disableOriginalConstructor()
+ ->onlyMethods(['getData'])
+ ->getMock();
+ $object->method('getData')->willReturn([
+ 'tracker' => 1,
+ 'status' => 'open',
+ 'values' => [
+ ['items_field', [12, 34]],
+ ],
+ ]);
+
+ $handler = new class ($object, false) extends Tiki_Profile_InstallHandler_TrackerItem {
+ public function replaceReferences(mixed &$data): void
+ {
+ }
+ };
+
+ $this->assertSame(123, $handler->doInstall());
+ }
+}
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/88e19051d45c07b47405c7b3342d0b12140c337e
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/88e19051d45c07b47405c7b3342d0b12140c337e
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs