Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
0cb4e831
Commit
0cb4e831
authored
3 years ago
by
Guillaume Heurtier
Browse files
Options
Downloads
Patches
Plain Diff
FIX #18516 TIME 1:35 migrate custom migrations
parent
c3223fea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
migration/20.03/migrateCustomNatures.php
+82
-0
82 additions, 0 deletions
migration/20.03/migrateCustomNatures.php
with
82 additions
and
0 deletions
migration/20.03/migrateCustomNatures.php
0 → 100755
+
82
−
0
View file @
0cb4e831
<?php
require
'../../vendor/autoload.php'
;
chdir
(
'../..'
);
// /!\ If nature label is set in a language file, only the 'fr' label will be migrated
require
'apps/maarch_entreprise/lang/fr.php'
;
const
DEFAULT_NATURES
=
[
'simple_mail'
,
'email'
,
'fax'
,
'chronopost'
,
'fedex'
,
'registered_mail'
,
'courier'
,
'message_exchange'
,
'other'
];
$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
]);
if
(
file_exists
(
"custom/
$custom
/apps/maarch_entreprise/lang/fr.php"
))
{
require
"custom/
$custom
/apps/maarch_entreprise/lang/fr.php"
;
}
$xmlfile
=
null
;
$path
=
"custom/
{
$custom
}
/apps/maarch_entreprise/xml/entreprise.xml"
;
if
(
!
file_exists
(
$path
))
{
continue
;
}
if
(
!
is_readable
(
$path
))
{
printf
(
"The file
$path
it is not readable or not writable.
\n
"
);
continue
;
}
$xmlfile
=
simplexml_load_file
(
$path
);
if
(
$xmlfile
)
{
if
(
!
empty
(
$xmlfile
->
mail_natures
->
nature
))
{
$natureCustomFieldId
=
1
;
// Custom field 'Nature' is created with id 1 during migration
$natureCustomField
=
\CustomField\models\CustomFieldModel
::
getById
([
'id'
=>
$natureCustomFieldId
]);
$natureCustomField
[
'values'
]
=
json_decode
(
$natureCustomField
[
'values'
],
true
);
foreach
(
$xmlfile
->
mail_natures
->
nature
as
$nature
)
{
if
(
in_array
(
$nature
->
id
,
DEFAULT_NATURES
))
{
continue
;
}
$natureLabel
=
(
string
)
$nature
->
label
;
if
(
!
empty
(
$natureLabel
)
&&
defined
(
$natureLabel
)
&&
constant
(
$natureLabel
)
!=
null
)
{
$natureLabel
=
constant
(
$natureLabel
);
}
$natureCustomField
[
'values'
][]
=
$natureLabel
;
$natureLabel
=
json_encode
(
$natureLabel
);
$natureLabel
=
str_replace
(
"'"
,
"''"
,
$natureLabel
);
\Resource\models\ResModel
::
update
([
'postSet'
=>
[
'custom_fields'
=>
"jsonb_set(custom_fields, '
{
{$natureCustomFieldId}
}
', '
{
$natureLabel
}
')"
],
'where'
=>
[
'res_id in (select res_id from mlb_coll_ext where nature_id = ?)'
],
'data'
=>
[(
string
)
$nature
->
id
]
]);
$migrated
++
;
}
\CustomField\models\CustomFieldModel
::
update
([
'set'
=>
[
'values'
=>
json_encode
(
$natureCustomField
[
'values'
])],
'where'
=>
[
'id = ?'
],
'data'
=>
[
$natureCustomFieldId
]
]);
}
}
printf
(
"Migration nature personnalisé (CUSTOM
{
$custom
}
) : "
.
$migrated
.
" nature(s) personnalisé(s) migré(s).
\n
"
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment