Skip to content

Commit d3c668a

Browse files
committed
Fix details & Apply suggestions
1 parent 92c24cd commit d3c668a

File tree

1 file changed

+6
-131
lines changed

1 file changed

+6
-131
lines changed

install/install.php

Lines changed: 6 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,7 @@ public function upgrade(Migration $migration, $args = []): bool {
226226
$this->createCronTasks();
227227
$this->createMiniDashboard();
228228
Config::setConfigurationValues('formcreator', ['schema_version' => PLUGIN_FORMCREATOR_SCHEMA_VERSION]);
229-
230-
// FORMCREATOR v3.0.0 - Trigger migration to GLPI 11 native forms
231-
if (version_compare(GLPI_VERSION, '11.0.0', '>=')) {
232-
$this->migrateToGlpi11NativeForms($args);
233-
}
234-
229+
235230
ob_get_flush();
236231

237232
if ($this->resyncIssues) {
@@ -469,7 +464,7 @@ protected function createNotifications() {
469464
// If it doesn't exists, create it
470465
if ($exists['cpt'] == 0) {
471466
$template_id = $template->add([
472-
'name' => Toolbox::addslashes_deep($data['name']),
467+
'name' => $data['name'],
473468
'comment' => '',
474469
'itemtype' => PluginFormcreatorFormAnswer::class,
475470
]);
@@ -478,14 +473,14 @@ protected function createNotifications() {
478473
$translation->add([
479474
'notificationtemplates_id' => $template_id,
480475
'language' => '',
481-
'subject' => Toolbox::addslashes_deep($data['subject']),
482-
'content_text' => Toolbox::addslashes_deep($data['content']),
483-
'content_html' => '<p>'.str_replace('\n', '<br />', Toolbox::addslashes_deep($data['content'])).'</p>',
476+
'subject' => $data['subject'],
477+
'content_text' => $data['content'],
478+
'content_html' => '<p>'.str_replace('\n', '<br />', $data['content']).'</p>',
484479
]);
485480

486481
// Create the notification
487482
$notification_id = $notification->add([
488-
'name' => Toolbox::addslashes_deep($data['name']),
483+
'name' => $data['name'],
489484
'comment' => '',
490485
'entities_id' => 0,
491486
'is_recursive' => 1,
@@ -1033,124 +1028,4 @@ protected function migrateFkToUnsignedInt() {
10331028
$this->migration->changeField($table, 'id', 'id', 'int ' . DBConnection::getDefaultPrimaryKeySignOption() . ' not null auto_increment');
10341029
}
10351030
}
1036-
1037-
/**
1038-
* Migrate Formcreator data to GLPI 11 native forms
1039-
* @param array $args CLI arguments
1040-
* @return bool
1041-
*/
1042-
private function migrateToGlpi11NativeForms(array $args = []): bool {
1043-
global $DB;
1044-
1045-
// Check if GLPI 11 migration class is available
1046-
if (!class_exists('\Glpi\Form\Migration\FormMigration')) {
1047-
$message = __('GLPI 11 Form Migration class not found. Make sure you are running GLPI 11.0.0 or higher.', 'formcreator');
1048-
if (isCommandLine()) {
1049-
echo "ERROR: " . $message . PHP_EOL;
1050-
} else {
1051-
Session::addMessageAfterRedirect($message, true, ERROR);
1052-
}
1053-
return false;
1054-
}
1055-
1056-
try {
1057-
// Check if migration is needed
1058-
$migrationNeeded = $this->isGlpi11MigrationNeeded();
1059-
if (!$migrationNeeded) {
1060-
$message = __('Formcreator data has already been migrated to GLPI 11 native forms.', 'formcreator');
1061-
if (isCommandLine()) {
1062-
echo "INFO: " . $message . PHP_EOL;
1063-
} else {
1064-
Session::addMessageAfterRedirect($message, true, INFO);
1065-
}
1066-
Config::setConfigurationValues('formcreator', ['migration_completed' => true]);
1067-
return true;
1068-
}
1069-
1070-
// Show migration start message
1071-
$message = __('Starting migration of Formcreator data to GLPI 11 native forms...', 'formcreator');
1072-
if (isCommandLine()) {
1073-
echo "INFO: " . $message . PHP_EOL;
1074-
} else {
1075-
Session::addMessageAfterRedirect($message, true, INFO);
1076-
}
1077-
1078-
// Initialize GLPI 11 migration
1079-
$migration = new \Glpi\Form\Migration\FormMigration($DB, \Glpi\Form\AccessControl\FormAccessControlManager::getInstance());
1080-
1081-
// Run the migration
1082-
$result = $migration->execute();
1083-
1084-
if ($result) {
1085-
// Mark migration as completed
1086-
Config::setConfigurationValues('formcreator', [
1087-
'migration_completed' => true,
1088-
'migration_date' => date('Y-m-d H:i:s'),
1089-
'migration_version' => PLUGIN_FORMCREATOR_VERSION
1090-
]);
1091-
1092-
$message = __('Formcreator data has been successfully migrated to GLPI 11 native forms!', 'formcreator');
1093-
if (isCommandLine()) {
1094-
echo "SUCCESS: " . $message . PHP_EOL;
1095-
echo "INFO: " . __('You can now use GLPI 11 native forms. Consider uninstalling Formcreator after verification.', 'formcreator') . PHP_EOL;
1096-
} else {
1097-
Session::addMessageAfterRedirect($message, true, INFO);
1098-
Session::addMessageAfterRedirect(
1099-
__('You can now use GLPI 11 native forms. Consider uninstalling Formcreator after verification.', 'formcreator'),
1100-
true,
1101-
INFO
1102-
);
1103-
}
1104-
1105-
return true;
1106-
} else {
1107-
$message = __('Migration to GLPI 11 native forms failed. Check GLPI logs for details.', 'formcreator');
1108-
if (isCommandLine()) {
1109-
echo "ERROR: " . $message . PHP_EOL;
1110-
} else {
1111-
Session::addMessageAfterRedirect($message, true, ERROR);
1112-
}
1113-
return false;
1114-
}
1115-
1116-
} catch (Exception $e) {
1117-
$message = sprintf(__('Migration failed with error: %s', 'formcreator'), $e->getMessage());
1118-
if (isCommandLine()) {
1119-
echo "ERROR: " . $message . PHP_EOL;
1120-
} else {
1121-
Session::addMessageAfterRedirect($message, true, ERROR);
1122-
}
1123-
1124-
// Log the full exception
1125-
Toolbox::logInFile('formcreator_migration', $e->getMessage() . PHP_EOL . $e->getTraceAsString());
1126-
1127-
return false;
1128-
}
1129-
}
1130-
1131-
/**
1132-
* Check if migration to GLPI 11 is needed
1133-
* @return bool
1134-
*/
1135-
private function isGlpi11MigrationNeeded(): bool {
1136-
global $DB;
1137-
1138-
// Check if migration was already completed
1139-
$migrationCompleted = Config::getConfigurationValue('formcreator', 'migration_completed');
1140-
if ($migrationCompleted) {
1141-
return false;
1142-
}
1143-
1144-
// Check if there are Formcreator forms to migrate
1145-
$formCount = 0;
1146-
if ($DB->tableExists('glpi_plugin_formcreator_forms')) {
1147-
$result = $DB->request([
1148-
'COUNT' => 'total',
1149-
'FROM' => 'glpi_plugin_formcreator_forms'
1150-
]);
1151-
$formCount = $result->current()['total'];
1152-
}
1153-
1154-
return $formCount > 0;
1155-
}
11561031
}

0 commit comments

Comments
 (0)