Skip to content

Commit d0f4117

Browse files
cconard96trasher
authored andcommitted
fix search SQL issues with custom assets
1 parent 4f6752c commit d0f4117

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

phpunit/functional/Glpi/Api/HL/Controller/AssetControllerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
namespace tests\units\Glpi\Api\HL\Controller;
3636

37+
use Glpi\Asset\Asset;
3738
use Glpi\Http\Request;
3839
use PHPUnit\Framework\Attributes\DataProvider;
3940

@@ -44,6 +45,9 @@ public function testIndex()
4445
global $CFG_GLPI;
4546
$types = $CFG_GLPI['asset_types'];
4647

48+
// Ignore custom assets
49+
$types = array_filter($types, static fn($t) => !is_subclass_of($t, Asset::class));
50+
4751
$this->login();
4852
$this->api->call(new Request('GET', '/Assets'), function ($call) use ($types) {
4953
/** @var \HLAPICallAsserter $call */

phpunit/functional/Glpi/Migration/GenericobjectPluginMigrationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use Glpi\Asset\Capacity\HasNotepadCapacity;
5151
use Glpi\Asset\Capacity\IsProjectAssetCapacity;
5252
use Glpi\Asset\Capacity\IsReservableCapacity;
53+
use Glpi\DBAL\QueryExpression;
5354
use Glpi\Dropdown\DropdownDefinition;
5455
use Glpi\Migration\GenericobjectPluginMigration;
5556
use Glpi\Migration\PluginMigrationResult;
@@ -94,6 +95,8 @@ public function setUp(): void
9495

9596
parent::setUp();
9697

98+
$DB->delete(AssetDefinition::getTable(), [new QueryExpression('true')]);
99+
97100
// Load it inside the test DB transaction to not have to clean it manually
98101
$queries = $DB->getQueriesFromFile(sprintf('%s/tests/fixtures/genericobject-migration/glpi-data.sql', GLPI_ROOT));
99102
foreach ($queries as $query) {
@@ -859,6 +862,7 @@ private function checkItems(string $class, array $expected_items): void
859862
}
860863
}
861864
}
865+
862866
$this->assertEquals(
863867
\count($expected_items),
864868
\countElementsInTable($class::getTable(), $class::getSystemSqlCriteria())

phpunit/functional/HtmlTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ public function testGetMenuInfos()
275275
'PassiveDCEquipment',
276276
'Unmanaged',
277277
'Cable',
278+
'Glpi\CustomAsset\Test01',
278279
'Item_DeviceSimcard',
279280
];
280281
$this->assertSame('Assets', $menu['assets']['title']);

src/Glpi/Asset/Asset.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,14 @@ public function rawSearchOptions()
267267
'id' => '49',
268268
'table' => Group::getTable(),
269269
'field' => 'completename',
270-
'linkfield' => 'groups_id_tech',
271270
'name' => __('Group in charge of the hardware'),
272271
'condition' => ['is_assign' => 1],
273272
'joinparams' => [
274273
'beforejoin' => [
275274
'table' => 'glpi_groups_items',
276275
'joinparams' => [
277276
'jointype' => 'itemtype_item',
278-
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_NORMAL],
277+
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_TECH],
279278
],
280279
],
281280
],

src/Glpi/Search/Provider/SQLProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4571,9 +4571,10 @@ public static function constructAdditionalSqlForMetacriteria(
45714571
$sopt["joinparams"]
45724572
);
45734573

4574+
$ref_table = $m_itemtype::getTable() . self::getMetaTableUniqueSuffix($m_itemtype::getTable(), $m_itemtype);
45744575
$FROM .= \Search::addLeftJoin(
45754576
$m_itemtype,
4576-
$m_itemtype::getTable(),
4577+
$ref_table,
45774578
$already_link_tables,
45784579
$sopt["table"],
45794580
$sopt["linkfield"],

tests/src/autoload/functions.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,36 @@ function loadDataset()
683683
'entities_id' => '_test_root_entity',
684684
],
685685
],
686+
'Glpi\\Asset\\AssetDefinition' => [
687+
[
688+
'system_name' => 'Test01',
689+
'icon' => 'ti ti-test-pipe',
690+
'label' => 'Test01',
691+
'is_active' => 1,
692+
'profiles' => ['4' => ALLSTANDARDRIGHT | READ_ASSIGNED | UPDATE_ASSIGNED | READ_OWNED | UPDATE_OWNED],
693+
],
694+
],
695+
'Glpi\\Asset\\CustomFieldDefinition' => [
696+
[
697+
'system_name' => 'teststring',
698+
'assets_assetdefinitions_id' => 'Test01',
699+
'label' => 'Test String',
700+
'type' => 'Glpi\\Asset\\CustomFieldType\\StringType',
701+
'field_options' => '{"full_width":"0","readonly":"0","required":"0"}',
702+
],
703+
],
704+
'Glpi\\CustomAsset\\Test01' => [
705+
[
706+
'name' => 'TestA',
707+
'entities_id' => '_test_root_entity',
708+
'custom_teststring' => 'Test String A',
709+
],
710+
[
711+
'name' => 'TestB',
712+
'entities_id' => '_test_root_entity',
713+
'custom_teststring' => 'Test String B',
714+
],
715+
],
686716
];
687717

688718
// To bypass various right checks

0 commit comments

Comments
 (0)