Skip to content
Snippets Groups Projects
Verified Commit a637aa7f authored by Giovannoni Laurent's avatar Giovannoni Laurent
Browse files

refactoring name of migration to 20.03

parent 44f8d224
No related branches found
No related tags found
No related merge requests found
Showing
with 3092 additions and 0 deletions
-- *************************************************************************--
-- --
-- --
-- Model migration script - 19.04 to 20.01 (Run this file after migrate.sh) --
-- --
-- --
-- *************************************************************************--
DROP VIEW IF EXISTS res_view_letterbox;
DROP VIEW IF EXISTS view_contacts;
DROP TABLE IF EXISTS cases;
DROP TABLE IF EXISTS cases_res;
DELETE FROM contacts_groups_lists WHERE contact_id IS NULL;
DROP TABLE IF EXISTS contacts_res;
DROP TABLE IF EXISTS contact_addresses;
DROP TABLE IF EXISTS contact_communication;
DROP TABLE IF EXISTS contact_purposes;
DROP TABLE IF EXISTS contact_types;
DROP TABLE IF EXISTS contacts_v2;
UPDATE CONTACTS SET civility = null WHERE civility = '';
UPDATE CONTACTS SET firstname = null WHERE firstname = '';
UPDATE CONTACTS SET lastname = null WHERE lastname = '';
UPDATE CONTACTS SET company = null WHERE company = '';
UPDATE CONTACTS SET department = null WHERE department = '';
UPDATE CONTACTS SET function = null WHERE function = '';
UPDATE CONTACTS SET address_number = null WHERE address_number = '';
UPDATE CONTACTS SET address_street = null WHERE address_street = '';
UPDATE CONTACTS SET address_additional1 = null WHERE address_additional1 = '';
UPDATE CONTACTS SET address_additional2 = null WHERE address_additional2 = '';
UPDATE CONTACTS SET address_postcode = null WHERE address_postcode = '';
UPDATE CONTACTS SET address_town = null WHERE address_town = '';
UPDATE CONTACTS SET address_country = null WHERE address_country = '';
UPDATE CONTACTS SET email = null WHERE email = '';
UPDATE CONTACTS SET phone = null WHERE phone = '';
UPDATE CONTACTS SET notes = null WHERE notes = '';
ALTER TABLE acknowledgement_receipts ALTER COLUMN contact_id set not null;
ALTER TABLE acknowledgement_receipts DROP COLUMN IF EXISTS contact_address_id;
ALTER TABLE contacts_groups_lists ALTER COLUMN contact_id set not null;
ALTER TABLE contacts_groups_lists DROP COLUMN IF EXISTS contact_addresses_id;
ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_contact_id;
ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_address_id;
ALTER TABLE res_attachments DROP COLUMN IF EXISTS dest_user;
ALTER TABLE contacts_filling DROP COLUMN IF EXISTS rating_columns;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS exp_contact_id;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS exp_user_id;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS dest_contact_id;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS dest_user_id;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS address_id;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS is_multicontacts;
DROP TABLE IF EXISTS fp_fileplan;
DROP TABLE IF EXISTS fp_fileplan_positions;
DROP TABLE IF EXISTS fp_res_fileplan_positions;
DROP TABLE IF EXISTS folder_tmp;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS folders_system_id;
DROP TABLE IF EXISTS groupbasket_status;
DROP TABLE IF EXISTS indexingmodels;
DROP TABLE IF EXISTS mlb_coll_ext;
DROP TABLE IF EXISTS res_version_attachments;
DROP TABLE IF EXISTS adr_attachments_version;
ALTER TABLE shippings DROP COLUMN IF EXISTS is_version;
ALTER TABLE priorities DROP COLUMN IF EXISTS default_priority;
DROP TABLE IF EXISTS doctypes_indexes;
DROP TABLE IF EXISTS listmodels;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t1;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t2;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t3;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t4;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t5;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t6;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t7;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t8;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t9;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t10;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t11;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t12;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t13;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t14;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_t15;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d1;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d2;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d3;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d4;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d5;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d6;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d7;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d8;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d9;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_d10;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_n1;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_n2;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_n3;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_n4;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_n5;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_f1;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_f2;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_f3;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_f4;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS custom_f5;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS scan_date;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS scan_user;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS scan_location;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS scan_wkstation;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS scan_batch;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS scan_postmark;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS description;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS author;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS reference_number;
ALTER TABLE res_letterbox DROP COLUMN IF EXISTS external_reference;
/* RE CREATE VIEWS */
CREATE OR REPLACE VIEW res_view_letterbox AS
SELECT r.res_id,
r.type_id,
r.policy_id,
r.cycle_id,
d.description AS type_label,
d.doctypes_first_level_id,
dfl.doctypes_first_level_label,
dfl.css_style AS doctype_first_level_style,
d.doctypes_second_level_id,
dsl.doctypes_second_level_label,
dsl.css_style AS doctype_second_level_style,
r.format,
r.typist,
r.creation_date,
r.modification_date,
r.docserver_id,
r.path,
r.filename,
r.fingerprint,
r.filesize,
r.status,
r.work_batch,
r.doc_date,
r.external_id,
r.external_link,
r.departure_date,
r.opinion_limit_date,
r.department_number_id,
r.barcode,
r.external_signatory_book_id,
r.initiator,
r.destination,
r.dest_user,
r.confidentiality,
r.category_id,
r.alt_identifier,
r.admission_date,
r.process_limit_date,
r.closing_date,
r.alarm1_date,
r.alarm2_date,
r.flag_alarm1,
r.flag_alarm2,
r.subject,
r.priority,
r.locker_user_id,
r.locker_time,
r.custom_fields,
en.entity_label,
en.entity_type AS entitytype
FROM doctypes d,
doctypes_first_level dfl,
doctypes_second_level dsl,
res_letterbox r
LEFT JOIN entities en ON r.destination::text = en.entity_id::text
WHERE r.type_id = d.type_id AND d.doctypes_first_level_id = dfl.doctypes_first_level_id AND d.doctypes_second_level_id = dsl.doctypes_second_level_id;
This diff is collapsed.
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$migrated = 0;
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$cases = \SrcCore\models\DatabaseModel::select([
'select' => ['case_id', 'case_label', 'case_closing_date'],
'table' => ['cases']
]);
if (!empty($cases)) {
$file = fopen("migration/20.03/cases_{$custom}.csv", 'w+');
$csvHead = ['Identifiant affaire', 'Libellé affaire', 'Date de cloture', 'Identifiant courrier', 'Numéro chrono', 'Sujet courrier'];
fputcsv($file, $csvHead, ',');
foreach ($cases as $case) {
$resources = \SrcCore\models\DatabaseModel::select([
'select' => ['r.res_id', 'r.subject', 'mlb.alt_identifier'],
'table' => ['cases_res c, res_letterbox r, mlb_coll_ext mlb'],
'where' => ['c.res_id = r.res_id', 'r.res_id = mlb.res_id', 'case_id = ?', 'r.status <> \'DEL\''],
'data' => [$case['case_id']]
]);
foreach ($resources as $resource) {
$csvContent = [$case['case_id'], $case['case_label'], $case['case_closing_date'], $resource['res_id'], $resource['alt_identifier'], $resource['subject']];
fputcsv($file, $csvContent, ',');
}
++$migrated;
}
fclose($file);
}
printf("Export Affaires (CUSTOM {$custom}) : " . $migrated . " Affaire(s) exportée(s) dans le fichier cases_{$custom}.csv\n");
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$migrated = 0;
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$fields = \SrcCore\models\DatabaseModel::select([
'select' => ['res_id', 'alt_identifier', 'custom_n1', 'custom_f1', 'custom_d1', 'custom_t2', 'custom_n2', 'custom_f2', 'custom_d2', 'custom_t3', 'custom_n3', 'custom_f3', 'custom_d3', 'custom_t4', 'custom_n4', 'custom_f4', 'custom_d4', 'custom_t5', 'custom_n5', 'custom_f5', 'custom_d5', 'custom_t6', 'custom_d6', 'custom_t7', 'custom_d7', 'custom_t8', 'custom_d8', 'custom_t9', 'custom_d9', 'custom_t10', 'custom_d10', 'custom_t11', 'custom_t12', 'custom_t13', 'custom_t14', 'custom_t15'],
'table' => ['res_letterbox'],
'where' => ['custom_n1 is not null or custom_f1 is not null or custom_d1 is not null or custom_t2 is not null or custom_n2 is not null or custom_f2 is not null or custom_d2 is not null or custom_t3 is not null or custom_n3 is not null or custom_f3 is not null or custom_d3 is not null or custom_t4 is not null or custom_n4 is not null or custom_f4 is not null or custom_d4 is not null or custom_t5 is not null or custom_n5 is not null or custom_f5 is not null or custom_d5 is not null or custom_t6 is not null or custom_d6 is not null or custom_t7 is not null or custom_d7 is not null or custom_t8 is not null or custom_d8 is not null or custom_t9 is not null or custom_d9 is not null or custom_t10 is not null or custom_d10 is not null or custom_t11 is not null or custom_t12 is not null or custom_t13 is not null or custom_t14 is not null or custom_t15 is not null']
]);
if (!empty($fields)) {
$file = fopen("migration/20.03/customFields_{$custom}.csv", 'w+');
$csvHead = ['Res id', 'Numéro chrono', 'custom_n1', 'custom_f1', 'custom_d1', 'custom_t2', 'custom_n2', 'custom_f2', 'custom_d2', 'custom_t3', 'custom_n3', 'custom_f3', 'custom_d3', 'custom_t4', 'custom_n4', 'custom_f4', 'custom_d4', 'custom_t5', 'custom_n5', 'custom_f5', 'custom_d5', 'custom_t6', 'custom_d6', 'custom_t7', 'custom_d7', 'custom_t8', 'custom_d8', 'custom_t9', 'custom_d9', 'custom_t10', 'custom_d10', 'custom_t11', 'custom_t12', 'custom_t13', 'custom_t14', 'custom_t15'];
fputcsv($file, $csvHead, ',');
foreach ($fields as $field) {
fputcsv($file, $field, ',');
$migrated++;
}
fclose($file);
}
printf("Export champs custom de res_letterbox (CUSTOM {$custom}) : " . $migrated . " Champ(s) exporté(s) dans le fichier customFields_{$custom}.csv\n");
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$migrated = 0;
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$fileplans = \SrcCore\models\DatabaseModel::select([
'select' => ['fileplan_id', 'fileplan_label'],
'table' => ['fp_fileplan'],
'where' => ['user_id is null']
]);
if (!empty($fileplans)) {
$file = fopen("migration/20.03/fileplans_{$custom}.csv", 'w+');
$csvHead = ['Identifiant plan', 'Libellé plan', 'Identifiant position', 'Libellé position', 'Identifiant courrier', 'Numéro chrono', 'Sujet courrier'];
fputcsv($file, $csvHead, ',');
foreach ($fileplans as $fileplan) {
$csvContent = [];
$positions = \SrcCore\models\DatabaseModel::select([
'select' => ['position_id', 'position_label'],
'table' => ['fp_fileplan_positions'],
'where' => ['fileplan_id = ?'],
'data' => [$fileplan['fileplan_id']]
]);
foreach ($positions as $position) {
$resources = \SrcCore\models\DatabaseModel::select([
'select' => ['r.res_id', 'r.subject', 'mlb.alt_identifier'],
'table' => ['fp_res_fileplan_positions p, res_letterbox r, mlb_coll_ext mlb'],
'where' => ['p.res_id = r.res_id', 'r.res_id = mlb.res_id', 'position_id = ?', 'r.status <> \'DEL\''],
'data' => [$position['position_id']]
]);
foreach ($resources as $resource) {
$csvContent = [$fileplan['fileplan_id'], $fileplan['fileplan_label'], $position['position_id'], $position['position_label'], $resource['res_id'], $resource['alt_identifier'], $resource['subject']];
fputcsv($file, $csvContent, ',');
}
}
if (!empty($csvContent)) {
++$migrated;
}
}
fclose($file);
}
printf("Export Plans de Classements (CUSTOM {$custom}) : " . $migrated . " Plan(s) de classement public exporté(s) dans le fichier fileplans_{$custom}.csv\n");
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$migrated = 0;
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$folders = \SrcCore\models\DatabaseModel::select([
'select' => ['f.folders_system_id', 'f.folder_name', 'f.status', 'r.res_id', 'mlb.alt_identifier', 'r.subject'],
'table' => ['folder_tmp f, res_letterbox r, mlb_coll_ext mlb'],
'where' => ['f.folders_system_id = r.folders_system_id', 'r.res_id = mlb.res_id', '(f.destination is null or f.destination = \'\')', 'f.status <> \'DEL\'', 'r.status <> \'DEL\''],
'order_by' => ['f.folder_name']
]);
if (!empty($folders)) {
$file = fopen("migration/20.03/folders_{$custom}.csv", 'w+');
$csvHead = ['Identifiant dossier', 'Libellé dossier', 'Statut dossier', 'Identifiant courrier', 'Numéro chrono', 'Sujet courrier'];
fputcsv($file, $csvHead, ',');
foreach ($folders as $folder) {
$csvContent = [$folder['folders_system_id'], $folder['folder_name'], $folder['status'], $folder['res_id'], $folder['alt_identifier'], $folder['subject']];
fputcsv($file, $csvContent, ',');
if (!empty($csvContent)) {
++$migrated;
}
}
fclose($file);
}
printf("Export Dossiers (CUSTOM {$custom}) : " . $migrated . " Dossier(s) public(s) exporté(s) dans le fichier folders_{$custom}.csv\n");
}
#!/bin/sh
php ./exportCustomFields.php
php ./exportCases.php
php ./exportFileplans.php
php ./exportFolders.php
php ./migrateCategories.php
php ./migrateCustomFields.php
php ./migrateFileplans.php
php ./migrateFolders.php
php ./migrateFullText.php
php ./migrateRedirectKeywords.php
php ./migrateIndexing.php
php ./migrateListTemplates.php
php ./migrateServicesEntities.php
php ./migrateMenuEntities.php
php ./removeProcessModes.php
php ./migrateOldIndexingModels.php
php ./migrateWorkingDays.php
php ./migrateExtensions.php
php ./migrateM2MConfiguration.php
php ./removeNatureFromPrint.php
php ./migrateCustomValues.php
php ./migrateVersionAttachments.php
php ./migrateContacts.php
# migrateOutgoingTemplate always before migrateTemplates
php ./migrateOutgoingTemplate.php
php ./migrateTemplates.php
php ./migrateLinkedResources.php
<?php
require '../../vendor/autoload.php';
chdir('../..');
$nonReadableFiles = [];
$migrated = 0;
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$path = "custom/{$custom}/apps/maarch_entreprise/xml/config.xml";
if (file_exists($path)) {
if (!is_readable($path) || !is_writable($path)) {
$nonReadableFiles[] = $path;
continue;
}
$loadedXml = simplexml_load_file($path);
if ($loadedXml) {
if (!empty($loadedXml->COLLECTION[0]->categories->category)) {
foreach ($loadedXml->COLLECTION[0]->categories->category as $category) {
$aCategories[] = (string)$category->id;
}
if (!empty($aCategories)) {
$indexingModels = \IndexingModel\models\IndexingModelModel::get([
'select'=> ['id'],
'where' => ['category not in (?)'],
'data' => [$aCategories]
]);
if (!empty($indexingModels)) {
$indexingModelsId = array_column($indexingModels, 'id');
\IndexingModel\models\IndexingModelFieldModel::delete([
'where' => ['model_id in (?)'],
'data' => [$indexingModelsId]
]);
}
\IndexingModel\models\IndexingModelModel::delete([
'where' => ['category not in (?)'],
'data' => [$aCategories]
]);
}
$defaultCategory = (string)$loadedXml->COLLECTION[0]->categories->default_category;
\IndexingModel\models\IndexingModelModel::update([
'set' => [
'"default"' => 'false'
],
'where' => ['1=?'],
'data' => [1]
]);
\IndexingModel\models\IndexingModelModel::update([
'set' => [
'"default"' => 'true'
],
'where' => ['category = ?'],
'data' => [$defaultCategory],
]);
}
$i = 0;
foreach ($loadedXml->COLLECTION as $value) {
unset($loadedXml->COLLECTION[$i]->categories);
$i++;
}
$res = formatXml($loadedXml);
$fp = fopen($path, "w+");
if ($fp) {
fwrite($fp, $res);
}
//Default Priority
$defaultPriority = \Priority\models\PriorityModel::get([
'select' => ['id'],
'where' => ['default_priority = ?'],
'data' => [1]
]);
if (!empty($defaultPriority)) {
\SrcCore\models\DatabaseModel::update([
'set' => ['default_value' => json_encode($defaultPriority[0]['id'])],
'table' => 'indexing_models_fields',
'where' => ['identifier = ?', 'model_id in (SELECT id FROM indexing_models WHERE private = FALSE)'],
'data' => ['priority']
]);
}
$migrated++;
}
}
}
foreach ($nonReadableFiles as $file) {
printf("The file %s it is not readable or not writable.\n", $file);
}
printf($migrated . " custom(s) avec config.xml (categorie) trouvé(s) et migré(s).\n");
function formatXml($simpleXMLElement)
{
$xmlDocument = new DOMDocument('1.0');
$xmlDocument->preserveWhiteSpace = false;
$xmlDocument->formatOutput = true;
$xmlDocument->loadXML($simpleXMLElement->asXML());
return $xmlDocument->saveXML();
}
This diff is collapsed.
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$migrated = 0;
$path = "custom/{$custom}/apps/maarch_entreprise/xml/index_letterbox.xml";
if (file_exists($path)) {
if (!is_readable($path) || !is_writable($path)) {
continue;
}
$loadedXml = simplexml_load_file($path);
if ($loadedXml) {
$indexingModels = \IndexingModel\models\IndexingModelModel::get(['select'=> ['id']]);
if (!empty($indexingModels)) {
$indexingModelsId = array_column($indexingModels, 'id');
}
$i = 0;
foreach ($loadedXml->INDEX as $value) {
$customExists = \SrcCore\models\DatabaseModel::select([
'select' => [1],
'table' => ['doctypes_indexes'],
'where' => ['field_name = ?'],
'data' => [(string)$value->column]
]);
if (empty($customExists)) {
continue;
}
$label = (string)$value->label;
$type = trim((string)$value->type);
if ($type == 'float') {
$type = 'integer';
}
$values = [];
if (!empty($value->values_list)) {
foreach ($value->values_list->value as $valueList) {
$values[] = (string)$valueList->label;
}
}
if (!empty($value->table) && !empty($value->table->table_name) && !empty($value->table->foreign_label)) {
$tableName = (string)$value->table->table_name;
$foreignLabel = (string)$value->table->foreign_label;
$whereClause = (string)$value->table->where_clause;
$order = (string)$value->table->order;
$customValues = \SrcCore\models\DatabaseModel::select([
'select' => [$foreignLabel],
'table' => [$tableName],
'where' => empty($whereClause) ? [] : [$whereClause],
'order_by' => [str_ireplace("order by", "", $order)]
]);
foreach ($customValues as $valueList) {
$values[] = $valueList[$foreignLabel];
}
}
$fieldId = \CustomField\models\CustomFieldModel::create([
'label' => $label,
'type' => $type,
'values' => empty($values) ? '[]' : json_encode($values)
]);
if (!empty($indexingModelsId)) {
foreach ($indexingModelsId as $indexingModelId) {
\IndexingModel\models\IndexingModelFieldModel::create([
'model_id' => $indexingModelId,
'identifier' => 'indexingCustomField_'.$fieldId,
'mandatory' => 'false',
'unit' => 'mail'
]);
}
}
$column = (string)$value->column;
$csColumn = "custom_fields->>''{$fieldId}''";
\Basket\models\BasketModel::update(['postSet' => ['basket_clause' => "REPLACE(basket_clause, '{$column}', '{$csColumn}')"], 'where' => ['1 = ?'], 'data' => [1]]);
\Basket\models\BasketModel::update(['postSet' => ['basket_clause' => "REPLACE(basket_clause, 'doc_{$column}', '{$csColumn}')"], 'where' => ['1 = ?'], 'data' => [1]]);
$resources = \Resource\models\ResModel::get([
'select' => ['res_id', $column],
'where' => [$column . ' is not null'],
]);
foreach ($resources as $resource) {
$valueColumn = json_encode($resource[$column]);
$valueColumn = str_replace("'", "''", $valueColumn);
$resId = $resource['res_id'];
\Resource\models\ResModel::update([
'postSet' => ['custom_fields' => "jsonb_set(custom_fields, '{{$fieldId}}', '{$valueColumn}')"],
'where' => ['res_id = ?'],
'data' => [$resId]
]);
}
$migrated++;
}
}
}
printf("Migration Champs Custom (CUSTOM {$custom}) : " . $migrated . " Champs custom utilisé(s) et migré(s).\n");
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$migrated = [];
// Migrate others Field
$migrateToCustom = [
['id' => 'description', 'label' => 'Autres informations', 'customType' => 'string', 'modelId' => [1, 2, 3, 4]],
['id' => 'external_reference', 'label' => 'Référence courrier expéditeur', 'customType' => 'string', 'modelId' => [1]],
['id' => 'reference_number', 'label' => 'N° recommandé', 'customType' => 'string', 'modelId' => [1, 2]],
['id' => 'scan_date', 'label' => 'Date de scan', 'customType' => 'date', 'modelId' => [1, 2]],
['id' => 'scan_user', 'label' => 'Utilisateur de scan', 'customType' => 'string', 'modelId' => [1, 2]],
['id' => 'scan_location', 'label' => 'Lieu de scan', 'customType' => 'string', 'modelId' => [1, 2]],
['id' => 'scan_wkstation', 'label' => 'Station de scan', 'customType' => 'string', 'modelId' => [1, 2]],
['id' => 'scan_batch', 'label' => 'Batch de scan', 'customType' => 'string', 'modelId' => [1, 2]],
['id' => 'scan_postmark', 'label' => 'Tampon de scan', 'customType' => 'string', 'modelId' => [1, 2]],
];
foreach ($migrateToCustom as $migration) {
if ($migration['customType'] == 'date') {
$where = [$migration['id'].' is not null'];
} else {
$where = [$migration['id'].' is not null', $migration['id'].' != \'\''];
}
$columnValues = \SrcCore\models\DatabaseModel::select([
'select' => ['res_id', $migration['id']],
'table' => ['res_letterbox'],
'where' => $where
]);
if (!empty($columnValues)) {
$fieldId = \CustomField\models\CustomFieldModel::create([
'label' => $migration['label'],
'type' => $migration['customType'],
'values' => '[]'
]);
$csColumn = "custom_fields->>''{$fieldId}''";
\Basket\models\BasketModel::update(['postSet' => ['basket_clause' => "REPLACE(basket_clause, '{$migration['id']}', '{$csColumn}')"], 'where' => ['1 = ?'], 'data' => [1]]);
foreach ($migration['modelId'] as $modelId) {
$indexingModels = \IndexingModel\models\IndexingModelModel::get([
'select'=> [1],
'where' => ['id = ?'],
'data' => [$modelId]
]);
if (!empty($indexingModels)) {
\IndexingModel\models\IndexingModelFieldModel::create([
'model_id' => $modelId,
'identifier' => 'indexingCustomField_'.$fieldId,
'mandatory' => 'false',
'unit' => 'mail'
]);
}
}
$aValues = [];
foreach ($columnValues as $columnValue) {
$aValues[] = [$columnValue['res_id'], $fieldId, json_encode($columnValue[$migration['id']])];
$valueColumn = json_encode($columnValue[$migration['id']]);
\Resource\models\ResModel::update([
'postSet' => ['custom_fields' => "jsonb_set(custom_fields, '{{$fieldId}}', '{$valueColumn}')"],
'where' => ['res_id = ?'],
'data' => [$columnValue['res_id']]
]);
}
$migrated[] = $migration['id'];
}
}
if (!empty($migrated)) {
$migrated = implode(',', $migrated);
printf("Migration vers les champs personnalisés (CUSTOM {$custom}) : Les champs suivants ont été migrés : " . $migrated . ".\n");
}
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$migrated = 0;
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$xmlfile = null;
$path = "custom/{$custom}/apps/maarch_entreprise/xml/extensions.xml";
if (file_exists($path)) {
$xmlfile = simplexml_load_file($path);
if ($xmlfile) {
$i = 0;
foreach ($xmlfile->FORMAT as $item) {
if (isset($item->index_frame_show)) {
$xmlfile->FORMAT[$i]->canConvert = $item->index_frame_show;
unset($xmlfile->FORMAT[$i]->index_frame_show);
}
++$i;
}
$res = $xmlfile->asXML();
$fp = fopen($path, "w+");
if ($fp) {
fwrite($fp, $res);
}
$migrated++;
}
}
}
printf("Migration Extensions : " . $migrated . " custom(s) avec un fichier extensions.xml trouvé(s) et migré(s).\n");
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$migrated = 0;
$fileplans = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['fp_fileplan']
]);
if (!empty($fileplans)) {
$superadmin = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => 'superadmin']);
if (empty($superadmin)) {
$firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1]);
$masterOwnerId = $firstMan[0]['id'];
} else {
$masterOwnerId = $superadmin['id'];
}
$masterFolderId = \Folder\models\FolderModel::create([
'label' => 'Reprise Plan de Classement',
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => null,
'level' => 0
]);
$GLOBALS['entities'] = \Entity\models\EntityModel::get(['select' => ['id']]);
fillEntities($masterFolderId);
foreach ($fileplans as $fileplan) {
$positions = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['fp_fileplan_positions'],
'where' => ['fileplan_id = ?'],
'data' => [$fileplan['fileplan_id']]
]);
if (empty($fileplan['user_id'])) {
$id = \Folder\models\FolderModel::create([
'label' => $fileplan['fileplan_label'],
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => $masterFolderId,
'level' => 1
]);
fillEntities($id);
foreach ($positions as $position) {
if (empty($position['parent_id'])) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => $id,
'level' => 2
]);
fillEntities($id);
runPositionsForPublic($positions, $position['position_id'], $id, 3, $masterOwnerId);
}
}
} else {
$user = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => $fileplan['user_id']]);
if (empty($user)) {
continue;
}
$id = \Folder\models\FolderModel::create([
'label' => $fileplan['fileplan_label'],
'public' => false,
'user_id' => $user['id'],
'parent_id' => null,
'level' => 0
]);
foreach ($positions as $position) {
if (empty($position['parent_id'])) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => false,
'user_id' => $user['id'],
'parent_id' => $id,
'level' => 1
]);
fillResources($id, $position['position_id']);
runPositionsForPrivate($positions, $position['position_id'], $id, 2, $user['id']);
}
}
}
++$migrated;
}
}
printf("Migration Plan de Classement (CUSTOM {$custom}) : " . $migrated . " Plan trouvé(s) et migré(s).\n");
}
function runPositionsForPublic($positions, $parentPositionId, $parentFolderId, $level, $masterOwnerId)
{
foreach ($positions as $position) {
if ($position['parent_id'] == $parentPositionId) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => $parentFolderId,
'level' => $level
]);
fillEntities($id);
runPositionsForPublic($positions, $position['position_id'], $id, $level + 1, $masterOwnerId);
break;
}
}
}
function runPositionsForPrivate($positions, $parentPositionId, $parentFolderId, $level, $ownerId)
{
foreach ($positions as $position) {
if ($position['parent_id'] == $parentPositionId) {
$id = \Folder\models\FolderModel::create([
'label' => $position['position_label'],
'public' => false,
'user_id' => $ownerId,
'parent_id' => $parentFolderId,
'level' => $level
]);
fillResources($id, $position['position_id']);
runPositionsForPrivate($positions, $position['position_id'], $id, $level + 1, $ownerId);
break;
}
}
}
function fillEntities($folderId)
{
foreach ($GLOBALS['entities'] as $entity) {
\Folder\models\EntityFolderModel::create([
'folder_id' => $folderId,
'entity_id' => $entity['id'],
'edition' => true,
]);
}
}
function fillResources($folderId, $positionId)
{
$resources = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['fp_res_fileplan_positions'],
'where' => ['position_id = ?', 'coll_id = ?'],
'data' => [$positionId, 'letterbox_coll']
]);
foreach ($resources as $resource) {
\Folder\models\ResourceFolderModel::create([
'folder_id' => $folderId,
'res_id' => $resource['res_id']
]);
}
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$migrated = 0;
$folders = \SrcCore\models\DatabaseModel::select([
'select' => ['folders_system_id', 'typist', 'destination', 'folder_name', 'parent_id'],
'table' => ['folder_tmp'],
'order_by' => ['folder_level asc']
]);
if (!empty($folders)) {
$superadmin = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => 'superadmin']);
if (empty($superadmin)) {
$firstMan = \User\models\UserModel::get(['select' => ['id'], 'orderBy' => ['id'], 'limit' => 1]);
$masterOwnerId = $firstMan[0]['id'];
} else {
$masterOwnerId = $superadmin['id'];
}
$masterFolderId = \Folder\models\FolderModel::create([
'label' => 'Reprise Dossier',
'public' => true,
'user_id' => $masterOwnerId,
'parent_id' => null,
'level' => 0
]);
$GLOBALS['entities'] = \Entity\models\EntityModel::get(['select' => ['id']]);
fillEntities($masterFolderId);
$aFolderIdMap = [];
foreach ($folders as $folder) {
$user = \User\models\UserModel::getByLogin(['select' => ['id'], 'login' => $folder['typist']]);
if (empty($folder['destination'])) {
// Public
if (empty($user)) {
$user['id'] = $masterOwnerId;
}
$folderId = \Folder\models\FolderModel::create([
'label' => $folder['folder_name'],
'public' => true,
'user_id' => $user['id'],
'parent_id' => empty($folder['parent_id']) ? $masterFolderId : $aFolderIdMap[$folder['parent_id']],
'level' => empty($folder['parent_id']) ? 1 : 2
]);
fillEntities($folderId);
} elseif (!empty($user)) {
// Private
$entity = \Entity\models\EntityModel::getByEntityId(['select' => ['id'], 'entityId' => $folder['destination']]);
if (empty($entity)) {
continue;
}
$folderId = \Folder\models\FolderModel::create([
'label' => $folder['folder_name'],
'public' => true,
'user_id' => $user['id'],
'parent_id' => $aFolderIdMap[$folder['parent_id']],
'level' => empty($folder['parent_id']) ? 0 : 1
]);
\Folder\models\EntityFolderModel::create([
'folder_id' => $folderId,
'entity_id' => $entity['id'],
'edition' => true,
]);
fillResources($folderId, $folder['folders_system_id']);
}
$aFolderIdMap[$folder['folders_system_id']] = $folderId;
++$migrated;
}
}
printf("Migration Dossier (CUSTOM {$custom}) : " . $migrated . " Dossier(s) trouvé(s) et migré(s).\n");
}
function fillEntities($folderId)
{
foreach ($GLOBALS['entities'] as $entity) {
\Folder\models\EntityFolderModel::create([
'folder_id' => $folderId,
'entity_id' => $entity['id'],
'edition' => true,
]);
}
}
function fillResources($folderId, $folderSystemId)
{
$resources = \SrcCore\models\DatabaseModel::select([
'select' => ['res_id'],
'table' => ['res_letterbox'],
'where' => ['folders_system_id = ?'],
'data' => [$folderSystemId]
]);
foreach ($resources as $resource) {
\Folder\models\ResourceFolderModel::create([
'folder_id' => $folderId,
'res_id' => $resource['res_id']
]);
}
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$migrated = 0;
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$xmlfile = null;
$path = "custom/{$custom}/apps/maarch_entreprise/xml/config.xml";
$xmlfile = simplexml_load_file($path);
if ($xmlfile) {
$i = 0;
foreach ($xmlfile->COLLECTION as $collection) {
if ((string)$collection->table == 'res_letterbox') {
$collId = 'letterbox_coll';
} elseif ((string)$collection->table == 'res_attachments') {
$collId = 'attachments_coll';
} else {
unset($xmlfile->COLLECTION[$i]);
continue;
}
\Docserver\models\DocserverModel::update([
'set' => [
'path_template' => (string)$collection->path_to_lucene_index
],
'where' => ['docserver_type_id = ?', 'coll_id = ?'],
'data' => ['FULLTEXT', $collId]
]);
unset($xmlfile->COLLECTION[$i]->path_to_lucene_index);
++$i;
}
$i = 0;
foreach ($xmlfile->MODULES as $module) {
if ((string)$module->moduleid == 'full_text') {
unset($xmlfile->MODULES[$i]);
break;
}
++$i;
}
$res = $xmlfile->asXML();
$fp = fopen($path, "w+");
if ($fp) {
fwrite($fp, $res);
}
$migrated++;
}
}
printf("Migration Full Text : " . $migrated . " custom(s) avec un fichier config.xml trouvé(s) et migré(s).\n");
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$groupBasket = \Basket\models\GroupBasketModel::get(['select' => ['group_id'], 'where' => ['basket_id = ?'], 'data' => ['IndexingBasket']]);
$migrated = 0;
foreach ($groupBasket as $value) {
$hasService = \SrcCore\models\DatabaseModel::select([
'select' => [1],
'table' => ['usergroups_services'],
'where' => ['group_id = ?', 'service_id = ?'],
'data' => [$value['group_id'], 'index_mlb']
]);
if (!empty($hasService)) {
$actions = [];
$entities = [];
$keywords = [];
\Group\models\GroupModel::update([
'set' => ['can_index' => 'true'],
'where' => ['group_id = ?'],
'data' => [$value['group_id']]
]);
// ACTIONS WITHOUT DIRECT STATUS
$actionsWithStatusesToCreate = \SrcCore\models\DatabaseModel::select([
'select' => ['status_id', 'action_id'],
'table' => ['groupbasket_status'],
'where' => ['group_id = ?', 'basket_id = ?'],
'data' => [$value['group_id'], 'IndexingBasket'],
'order_by' => ['"order"']
]);
foreach ($actionsWithStatusesToCreate as $item) {
$existingActions = \SrcCore\models\DatabaseModel::select([
'select' => ['id'],
'table' => ['actions'],
'where' => ['id_status = ?', '(action_page = ? OR component = ?)'],
'data' => [$item['status_id'], 'confirm_status', 'confirmAction']
]);
if (!empty($existingActions[0])) {
$actions[] = (string)$existingActions[0]['id'];
} else {
$statusLabel = \Status\models\StatusModel::getById(['id' => $item['status_id'], 'select' => ['label_status']]);
$id = \Action\models\ActionModel::create([
'label_action' => "Enregistrer vers le status : {$statusLabel['label_status']}" ,
'id_status' => $item['status_id'],
'history' => 'Y',
'component' => 'confirmAction'
]);
\Action\models\ActionModel::createCategories(['id' => $id, 'categories' => ['incoming', 'outgoing', 'internal', 'ged_doc']]);
$actions[] = (string)$id;
}
}
// ACTIONS WITH STATUS
$actionsToMigrate = \SrcCore\models\DatabaseModel::select([
'select' => ['id_action'],
'table' => ['actions_groupbaskets, actions'],
'where' => ['group_id = ?', 'basket_id = ?', 'id_action = id', '(action_page = ? OR component = ? OR action_page = ?)'],
'data' => [$value['group_id'], 'IndexingBasket', 'confirm_status', 'confirmAction', "''"]
]);
foreach ($actionsToMigrate as $item) {
if (!in_array($item['id_action'], $actions)) {
$actions[] = (string)$item['id_action'];
}
}
// KEYWORDS + ENTITIES
$keywordsAndEntities = \SrcCore\models\DatabaseModel::select([
'select' => ['entity_id', 'keyword'],
'table' => ['groupbasket_redirect'],
'where' => ['group_id = ?', 'basket_id = ?', 'redirect_mode = ?'],
'data' => [$value['group_id'], 'IndexingBasket', 'ENTITY']
]);
foreach ($keywordsAndEntities as $item) {
if (!empty($item['keyword']) && !in_array($item['keyword'], $keywords)) {
$keywords[] = $item['keyword'];
} elseif (!empty($item['entity_id'])) {
$entityToMigrate = \Entity\models\EntityModel::getByEntityId(['entityId' => $item['entity_id'], 'select' => ['id']]);
if (!in_array($entityToMigrate['id'], $entities)) {
$entities[] = (string)$entityToMigrate['id'];
}
}
}
// UPDATE INDEXING PARAMS
\Group\models\GroupModel::update([
'set' => ['indexation_parameters' => json_encode(['actions' => $actions, 'entities' => $entities, 'keywords' => $keywords])],
'where' => ['group_id = ?'],
'data' => [$value['group_id']]
]);
$migrated++;
}
}
\SrcCore\models\DatabaseModel::delete([
'table' => 'groupbasket',
'where' => ['basket_id = ?'],
'data' => ['IndexingBasket']
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'actions_groupbaskets',
'where' => ['basket_id = ?'],
'data' => ['IndexingBasket']
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'groupbasket_redirect',
'where' => ['basket_id = ?'],
'data' => ['IndexingBasket']
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'groupbasket_status',
'where' => ['basket_id = ?'],
'data' => ['IndexingBasket']
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'users_baskets_preferences',
'where' => ['basket_id = ?'],
'data' => ['IndexingBasket']
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'baskets',
'where' => ['basket_id = ?'],
'data' => ['IndexingBasket']
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'usergroups_services',
'where' => ['service_id = ?'],
'data' => ['index_mlb']
]);
printf("Migration Indexing Basket (CUSTOM {$custom}) : " . $migrated . " groupe(s) avec le service et la bannette IndexingBasket trouvé(s) et migré(s).\n");
//MIGRATION ACTIONS AVEC STATUS
$basketsWithStatuses = \SrcCore\models\DatabaseModel::select([
'select' => ['group_id', 'basket_id', 'status_id', 'action_id'],
'table' => ['groupbasket_status']
]);
$migrated = 0;
$actionsToDelete = [];
foreach ($basketsWithStatuses as $value) {
if (!in_array($value['action_id'], $actionsToDelete)) {
$actionsToDelete[] = $value['action_id'];
}
$existingActions = \SrcCore\models\DatabaseModel::select([
'select' => ['id'],
'table' => ['actions'],
'where' => ['id_status = ?', '(action_page = ? OR component = ?)'],
'data' => [$value['status_id'], 'confirm_status', 'confirmAction']
]);
if (!empty($existingActions[0])) {
$id = (string)$existingActions[0]['id'];
} else {
$statusLabel = \Status\models\StatusModel::getById(['id' => $value['status_id'], 'select' => ['label_status']]);
$id = \Action\models\ActionModel::create([
'label_action' => "Enregistrer vers le status : {$statusLabel['label_status']}" ,
'id_status' => $value['status_id'],
'history' => 'Y',
'component' => 'confirmAction'
]);
\Action\models\ActionModel::createCategories(['id' => $id, 'categories' => ['incoming', 'outgoing', 'internal', 'ged_doc']]);
}
$actionAlreadyExists = \Basket\models\ActionGroupBasketModel::get([
'select' => [1],
'where' => ['group_id = ?', 'basket_id = ?', 'id_action = ?'],
'data' => [$value['group_id'], $value['basket_id'], $id]
]);
if (empty($actionAlreadyExists)) {
\Basket\models\ActionGroupBasketModel::create([
'id' => $value['basket_id'],
'groupId' => $value['group_id'],
'actionId' => $id,
'whereClause' => '',
'usedInBasketlist' => 'N',
'usedInActionPage' => 'Y',
'defaultActionList' => 'N'
]);
}
$migrated++;
}
if (!empty($actionsToDelete)) {
\SrcCore\models\DatabaseModel::delete([
'table' => 'actions',
'where' => ['id in (?)'],
'data' => [$actionsToDelete]
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'actions_groupbaskets',
'where' => ['id_action in (?)'],
'data' => [$actionsToDelete]
]);
\SrcCore\models\DatabaseModel::delete([
'table' => 'actions_categories',
'where' => ['action_id in (?)'],
'data' => [$actionsToDelete]
]);
}
\SrcCore\models\DatabaseModel::update([
'set' => ['keyword' => ''],
'table' => 'actions',
'where' => ['keyword = ?'],
'data' => ['indexing']
]);
printf("Migration Indexing Basket (CUSTOM {$custom}) : " . $migrated . " action(s) avec des status (mot clé indexation) trouvé(s) et migré(s).\n");
}
<?php
use Resource\models\ResModel;
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$migrated = 0;
$links = \SrcCore\models\DatabaseModel::select([
'select' => ['res_parent', 'res_child'],
'table' => ['res_linked']
]);
foreach ($links as $link) {
$resParent = (string)$link['res_parent'];
$resChild = (string)$link['res_child'];
ResModel::update([
'postSet' => ['linked_resources' => "jsonb_insert(linked_resources, '{0}', '\"{$resChild}\"')"],
'where' => ['res_id = ?', "(linked_resources @> ?) = false"],
'data' => [(int)$resParent, "\"{$resChild}\""]
]);
ResModel::update([
'postSet' => ['linked_resources' => "jsonb_insert(linked_resources, '{0}', '\"{$resParent}\"')"],
'where' => ['res_id = ?', "(linked_resources @> ?) = false"],
'data' => [(int)$resChild, "\"{$resParent}\""]
]);
$migrated++;
}
printf("Migration des liaisons dans res_letterbox (CUSTOM {$custom}) : " . $migrated . " liaisons migrés.\n");
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$migrated = 0;
\SrcCore\models\DatabasePDO::reset();
new \SrcCore\models\DatabasePDO(['customId' => $custom]);
$listModels = \SrcCore\models\DatabaseModel::select([
'select' => ['*'],
'table' => ['listmodels'],
'order_by' => ['sequence', 'id']
]);
$formattedListModels = [];
foreach ($listModels as $listModel) {
$formattedId = $listModel['object_id'].$listModel['object_type'];
if (empty($formattedListModels[$formattedId])) {
$formattedListModels[$formattedId] = [
'object_id' => $listModel['object_id'],
'object_type' => $listModel['object_type'],
'title' => $listModel['title'],
'description' => $listModel['description'],
'items' => [$listModel]
];
} else {
$formattedListModels[$formattedId]['items'][] = $listModel;
}
}
foreach ($formattedListModels as $value) {
$entityId = null;
if (strpos($value['object_id'], 'VISA_CIRCUIT_') === false && strpos($value['object_id'], 'AVIS_CIRCUIT_') === false) {
$entity = \Entity\models\EntityModel::getByEntityId(['entityId' => $value['object_id'], 'select' => ['id']]);
$entityId = $entity['id'];
}
$type = $value['object_type'] == 'entity_id' ? 'diffusionList' : ($value['object_type'] == 'VISA_CIRCUIT' ? 'visaCircuit' : 'opinionCircuit');
if (!empty($value['title'])) {
$title = $value['title'];
} elseif (!empty($value['description'])) {
$title = $value['description'];
} else {
$title = $value['object_id'];
}
$listTemplateId = \Entity\models\ListTemplateModel::create([
'title' => $title,
'description' => $value['description'],
'type' => $type,
'entity_id' => $entityId
]);
foreach ($value['items'] as $key => $item) {
if (empty($item['item_id'])) {
continue;
}
if ($item['item_type'] == 'user_id') {
$itemId = \User\models\UserModel::getByLogin(['login' => $item['item_id'], 'select' => ['id']]);
} else {
$itemId = \Entity\models\EntityModel::getByEntityId(['entityId' => $item['item_id'], 'select' => ['id']]);
}
if (empty($itemId['id'])) {
continue;
}
\Entity\models\ListTemplateItemModel::create([
'list_template_id' => $listTemplateId,
'item_id' => $itemId['id'],
'item_type' => $item['item_type'] == 'user_id' ? 'user' : 'entity',
'item_mode' => $item['item_mode'],
'sequence' => $key
]);
}
++$migrated;
}
printf("Migration List templates (CUSTOM {$custom}) : " . $migrated . " modèles de listes trouvé(s) et migré(s).\n");
}
<?php
require '../../vendor/autoload.php';
chdir('../..');
$migrated = 0;
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$xmlfile = null;
$path = "custom/{$custom}/apps/maarch_entreprise/xml/m2m_config.xml";
if (file_exists($path)) {
$xmlfile = simplexml_load_file($path);
if ($xmlfile) {
$xmlfile->indexingModelId = 1;
unset($xmlfile->contacts_v2);
unset($xmlfile->contact_addresses);
$res = $xmlfile->asXML();
$fp = fopen($path, "w+");
if ($fp) {
fwrite($fp, $res);
}
$migrated++;
}
}
}
printf("Migration m2m configuration : " . $migrated . " custom(s) avec un fichier m2m_config.xml trouvé(s) et migré(s).\n");
<?php
require '../../vendor/autoload.php';
chdir('../..');
$nonReadableFiles = [];
$migrated = 0;
$customs = scandir('custom');
foreach ($customs as $custom) {
if ($custom == 'custom.xml' || $custom == '.' || $custom == '..') {
continue;
}
$natures = [];
$path = "custom/{$custom}/modules/entities/xml/menu.xml";
if (file_exists($path)) {
if (!is_readable($path) || !is_writable($path)) {
$nonReadableFiles[] = $path;
continue;
}
$loadedXml = simplexml_load_file($path);
if ($loadedXml) {
$i = 0;
foreach ($loadedXml->MENU as $value) {
if ($value->id == 'entities_print_sep_mlb') {
$loadedXml->MENU[$i]->url = '/separators/print';
$loadedXml->MENU[$i]->angular = 'true';
break;
}
++$i;
}
$res = formatXml($loadedXml);
$fp = fopen($path, "w+");
if ($fp) {
fwrite($fp, $res);
$migrated++;
}
}
}
}
foreach ($nonReadableFiles as $file) {
printf("The file %s it is not readable or not writable.\n", $file);
}
printf($migrated . " custom(s) avec menu.xml (entities) trouvé(s) et migré(s).\n");
function formatXml($simpleXMLElement)
{
$xmlDocument = new DOMDocument('1.0');
$xmlDocument->preserveWhiteSpace = false;
$xmlDocument->formatOutput = true;
$xmlDocument->loadXML($simpleXMLElement->asXML());
return $xmlDocument->saveXML();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment