Skip to content

Commit

Permalink
Replace direct query() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Oct 25, 2023
1 parent f3dd388 commit 883f59d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
7 changes: 4 additions & 3 deletions tests/Installation/DatabaseTestsCommons.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ public function checkInstall($pluginname = '', $when = '')
/*
* Verify in taskjob definition PluginFusinvsnmpIPRange not exist
*/
$query = "SELECT * FROM `glpi_plugin_glpiinventory_taskjobs`";
$result = $DB->query($query);
while ($data = $DB->fetchArray($result)) {
$request = $DB->request([
'FROM' => 'glpi_plugin_glpiinventory_taskjobs'
]);
foreach ($request as $data) {
$snmprangeip = 0;
if (strstr($data['targets'], "PluginFusinvsnmpIPRange")) {
$snmprangeip = 1;
Expand Down
19 changes: 14 additions & 5 deletions tests/Integration/RestURLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class RestURLTest extends TestCase
{
public static function setUpBeforeClass(): void
{

// Delete all entities except root entity
$entity = new Entity();
$items = $entity->find();
Expand Down Expand Up @@ -100,15 +99,19 @@ public function prepareDb()
$ret = $entity->update($input);
$this->assertTrue($ret);

// active all modules
$query = "UPDATE `glpi_plugin_glpiinventory_agentmodules`"
. " SET `is_active`='1'";
$DB->query($query);
// active all modules
$DB->update(
'glpi_plugin_glpiinventory_agentmodules',
['is_active' => 1],
[new QueryExpression("1=1")]
);
}


/**
* @test
*
* @depends prepareDb
*/
public function getCollectUrlEnt1Entity()
{
Expand Down Expand Up @@ -146,6 +149,8 @@ public function getCollectUrlEnt1Entity()

/**
* @test
*
* @depends prepareDb
*/
public function getDeployUrlRootEntity()
{
Expand Down Expand Up @@ -182,6 +187,8 @@ public function getDeployUrlRootEntity()

/**
* @test
*
* @depends prepareDb
*/
public function getEsxUrlRootEntity()
{
Expand Down Expand Up @@ -218,6 +225,8 @@ public function getEsxUrlRootEntity()

/**
* @test
*
* @depends prepareDb
*/
public function getCollectUrlRootEntity()
{
Expand Down
24 changes: 15 additions & 9 deletions tests/Integration/Tasks/CronTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,11 @@ public function cleanTasksAndJobs()
$datetime = new Datetime($_SESSION['glpi_currenttime']);
$datetime->modify('-4 days');

$query = "UPDATE `glpi_plugin_glpiinventory_taskjoblogs`
SET `date`='" . $datetime->format('Y-m-d') . " 00:00:00'";
$DB->query($query);
$DB->update(
'glpi_plugin_glpiinventory_taskjoblogs',
['date' => $datetime->format('Y-m-d') . " 00:00:00"],
[new QueryExpression("1=1")]
);

//No task & jobs should be removed because ask for cleaning 5 days from now
$index = $pfTask->cleanTasksAndJobs(5);
Expand Down Expand Up @@ -770,15 +772,19 @@ public function cleanTasksAndJobs()
));

//Set the first job as successfull
$query = "SELECT DISTINCT `plugin_glpiinventory_taskjobstates_id`
FROM glpi_plugin_glpiinventory_taskjoblogs";
foreach ($DB->request($query) as $data) {
$request = $DB->request([
'DISTINCT' => 'plugin_glpiinventory_taskjobstates_id',
'FROM' => 'glpi_plugin_glpiinventory_taskjoblogs',
]);
foreach ($request as $data) {
$pfTaskJobstate->changeStatusFinish($data['plugin_glpiinventory_taskjobstates_id'], 0, '');
}

$query = "UPDATE `glpi_plugin_glpiinventory_taskjoblogs`
SET `date`='" . $datetime->format('Y-m-d') . " 00:00:00'";
$DB->query($query);
$DB->update(
'glpi_plugin_glpiinventory_taskjoblogs',
['date' => $datetime->format('Y-m-d') . " 00:00:00"],
[new QueryExpression("1=1")]
);

//One taskjob is finished and should be cleaned
$index = $pfTask->cleanTasksAndJobs(2);
Expand Down
39 changes: 32 additions & 7 deletions tests/Unit/Deploy/PackageJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,18 @@ public function Migration_to_91()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;";
$DB->doQuery($query);

$query = "INSERT INTO `glpi_plugin_glpiinventory_deploypackages` (`id`, `name`, `comment`, `entities_id`, `is_recursive`, `date_mod`, `uuid`) VALUES
(16, 'INST VLC 2.1.5', 'Install VLC 2.1.5 unintall all VLC', 0, 0, '2014-10-17 11:11:02', NULL);";
$DB->query($query);
$DB->insert(
'glpi_plugin_glpiinventory_deploypackages',
[
'id' => 16,
'name' => 'INST VLC 2.1.5',
'comment' => 'Install VLC 2.1.5 unintall all VLC',
'entities_id' => 0,
'is_recursive' => 0,
'date_mod' => '2014-10-17 11:11:02',
'uuid' => null
]
);

// glpi_plugin_glpiinventory_deployorders
$DB->dropTable('glpi_plugin_glpiinventory_deployorders', true);
Expand All @@ -147,11 +156,27 @@ public function Migration_to_91()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;";
$DB->doQuery($query);

$query = "INSERT INTO `glpi_plugin_glpiinventory_deployorders` (`id`, `type`, `create_date`, `plugin_glpiinventory_deploypackages_id`, `json`) VALUES
(31, 0, '2013-04-29 09:58:58', 16, '{\"jobs\":{\"checks\":[],\"actions\":[{\"mkdir\":{\"list\":[\"c:\\\\packages\\\\vlc\"]}},{\"move\":{\"from\":\"*.*\",\"to\":\"c:\\\\packages\\\\vlc\"}},{\"cmd\":{\"exec\":\"c:\\\\packages\\\\vlc\\\\vlcinstall.cmd\"}}],\"associatedFiles\":[\"1f54a4730571d165a488f7f343e49d71f7e06c639091959df7065019971d1c3080f97da6517a94173083a50625dc1c1ba11f685d0c6f15705a75d5265c708cee\"]},\"associatedFiles\":{\"1f54a4730571d165a488f7f343e49d71f7e06c639091959df7065019971d1c3080f97da6517a94173083a50625dc1c1ba11f685d0c6f15705a75d5265c708cee\":{\"name\":\"vlc.zip\",\"p2p\":1,\"p2p-retention-duration\":16,\"uncompress\":1}}}'),
(32, 1, '2013-04-29 09:58:58', 16, '{\"jobs\":{\"checks\":[],\"actions\":[{\"cmd\":{\"exec\":\"vlcuninstall.cmd\"}}],\"associatedFiles\":[\"b16d6a078538842df7b6e572be62845b16870d5f325ec39ac4ae3d6705b2845990684c5a39206c7f23db177226781660324fab14330d98e71f2315658d13584b\"]},\"associatedFiles\":{\"b16d6a078538842df7b6e572be62845b16870d5f325ec39ac4ae3d6705b2845990684c5a39206c7f23db177226781660324fab14330d98e71f2315658d13584b\":{\"name\":\"vlcuninstall.cmd\",\"p2p\":0,\"p2p-retention-duration\":5,\"uncompress\":0}}}');";
$DB->insert(
'glpi_plugin_glpiinventory_deployorders',
[
'id' => 31,
'type' => 0,
'create_date' => '2013-04-29 09:58:58',
'plugin_glpiinventory_deploypackages_id' => 16,
'json' => '{\"jobs\":{\"checks\":[],\"actions\":[{\"mkdir\":{\"list\":[\"c:\\\\packages\\\\vlc\"]}},{\"move\":{\"from\":\"*.*\",\"to\":\"c:\\\\packages\\\\vlc\"}},{\"cmd\":{\"exec\":\"c:\\\\packages\\\\vlc\\\\vlcinstall.cmd\"}}],\"associatedFiles\":[\"1f54a4730571d165a488f7f343e49d71f7e06c639091959df7065019971d1c3080f97da6517a94173083a50625dc1c1ba11f685d0c6f15705a75d5265c708cee\"]},\"associatedFiles\":{\"1f54a4730571d165a488f7f343e49d71f7e06c639091959df7065019971d1c3080f97da6517a94173083a50625dc1c1ba11f685d0c6f15705a75d5265c708cee\":{\"name\":\"vlc.zip\",\"p2p\":1,\"p2p-retention-duration\":16,\"uncompress\":1}}}'
]
);
$DB->insert(
'glpi_plugin_glpiinventory_deployorders',
[
'id' => 32,
'type' => 1,
'create_date' => '2013-04-29 09:58:58',
'plugin_glpiinventory_deploypackages_id' => 16,
'json' => '{\"jobs\":{\"checks\":[],\"actions\":[{\"cmd\":{\"exec\":\"vlcuninstall.cmd\"}}],\"associatedFiles\":[\"b16d6a078538842df7b6e572be62845b16870d5f325ec39ac4ae3d6705b2845990684c5a39206c7f23db177226781660324fab14330d98e71f2315658d13584b\"]},\"associatedFiles\":{\"b16d6a078538842df7b6e572be62845b16870d5f325ec39ac4ae3d6705b2845990684c5a39206c7f23db177226781660324fab14330d98e71f2315658d13584b\":{\"name\":\"vlcuninstall.cmd\",\"p2p\":0,\"p2p-retention-duration\":5,\"uncompress\":0}}}'
]
);

$DB->query($query);
// run migration packages
require_once(PLUGIN_GLPI_INVENTORY_DIR . "/install/update.php");
$migration = new Migration('9.1');
Expand Down

0 comments on commit 883f59d

Please sign in to comment.