Skip to content

Commit 99eb790

Browse files
committed
fix(install): fix inconsistencies in install process"
1 parent c907214 commit 99eb790

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

install/install.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public function install(Migration $migration) {
1919
$this->configureExistingEntities();
2020
$this->createRequestType();
2121
$this->createDefaultDisplayPreferences();
22+
$this->createCronTasks();
2223
$this->createNotifications();
23-
2424
Config::setConfigurationValues('formcreator', ['schema_version' => PLUGIN_FORMCREATOR_SCHEMA_VERSION]);
2525

2626
return true;
@@ -64,6 +64,7 @@ public function upgrade(Migration $migration) {
6464
$this->configureExistingEntities();
6565
$this->createRequestType();
6666
$this->createDefaultDisplayPreferences();
67+
$this->createCronTasks();
6768
Config::setConfigurationValues('formcreator', ['schema_version' => PLUGIN_FORMCREATOR_SCHEMA_VERSION]);
6869

6970
return true;
@@ -439,4 +440,16 @@ public function uninstall() {
439440
$config = new Config();
440441
$config->deleteByCriteria(['context' => 'formcreator']);
441442
}
443+
444+
/**
445+
* Create cron tasks
446+
*/
447+
protected function createCronTasks() {
448+
CronTask::Register(PluginFormcreatorIssue::class, 'SyncIssues', HOUR_TIMESTAMP,
449+
[
450+
'comment' => __('Formcreator - Sync service catalog issues', 'formcreator'),
451+
'mode' => CronTask::MODE_EXTERNAL
452+
]
453+
);
454+
}
442455
}

tests/0000_Install/PluginInstallTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ protected function setupGLPI() {
4949
$CFG_GLPI = $settings + $CFG_GLPI;
5050
}
5151

52+
/**
53+
* @engine inline
54+
*/
5255
public function testInstallPlugin() {
5356
global $DB;
5457

5558
$this->setupGLPI();
5659

57-
$this->assertTrue($DB->connected, "Problem connecting to the Database");
60+
$this->assertTrue($DB->connected, 'Problem connecting to the Database');
5861

5962
$this->login('glpi', 'glpi');
6063

@@ -63,12 +66,12 @@ public function testInstallPlugin() {
6366
$config->deleteByCriteria(array('context' => 'formcreator'));
6467

6568
// Drop tables of the plugin if they exist
66-
$query = "SHOW TABLES";
69+
$query = 'SHOW TABLES';
6770
$result = $DB->query($query);
6871
while ($data = $DB->fetch_array($result)) {
6972

70-
if (strstr($data[0], "glpi_plugin_formcreator") !== false) {
71-
$DB->query("DROP TABLE ".$data[0]);
73+
if (strstr($data[0], 'glpi_plugin_formcreator') !== false) {
74+
$DB->query('DROP TABLE '.$data[0]);
7275
}
7376
}
7477

@@ -82,15 +85,21 @@ public function testInstallPlugin() {
8285
ob_end_clean();
8386

8487
$PluginDBTest = new PluginDB();
85-
$PluginDBTest->checkInstall("formcreator", "install");
88+
$PluginDBTest->checkInstall('formcreator', 'install');
8689

90+
// Check the version of the schema is saved
8791
$config = Config::getConfigurationValues('formcreator');
8892
$this->assertArrayHasKey('schema_version', $config);
89-
$this->assertEquals($config['schema_version'], PLUGIN_FORMCREATOR_SCHEMA_VERSION);
93+
$this->assertEquals(PLUGIN_FORMCREATOR_SCHEMA_VERSION, $config['schema_version']);
94+
95+
// Check the cron task is created
96+
$cronTask = new CronTask();
97+
$cronTask->getFromDBbyName(PluginFormcreatorIssue::class, 'SyncIssues');
98+
$this->assertFalse($cronTask->isNewItem());
9099

91100
// Enable the plugin
92101
$plugin->activate($plugin->fields['id']);
93-
$this->assertTrue($plugin->isActivated("formcreator"), "Cannot enable the plugin");
102+
$this->assertTrue($plugin->isActivated('formcreator'), 'Cannot enable the plugin');
94103

95104
}
96105
}

0 commit comments

Comments
 (0)