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
17d3784a
Commit
17d3784a
authored
5 years ago
by
Guillaume Heurtier
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #11780 TIME 2:00 added merging tags
parent
19a6aab3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rest/index.php
+1
-0
1 addition, 0 deletions
rest/index.php
src/app/tag/controllers/TagController.php
+72
-0
72 additions, 0 deletions
src/app/tag/controllers/TagController.php
src/app/tag/models/TagModel.php
+75
-0
75 additions, 0 deletions
src/app/tag/models/TagModel.php
with
148 additions
and
0 deletions
rest/index.php
+
1
−
0
View file @
17d3784a
...
...
@@ -373,6 +373,7 @@ $app->get('/tags', \Tag\controllers\TagController::class . ':get');
$app
->
post
(
'/tags'
,
\Tag\controllers\TagController
::
class
.
':create'
);
$app
->
get
(
'/tags/{id}'
,
\Tag\controllers\TagController
::
class
.
':getById'
);
$app
->
put
(
'/tags/{id}'
,
\Tag\controllers\TagController
::
class
.
':update'
);
$app
->
put
(
'/tags/{id}/merge'
,
\Tag\controllers\TagController
::
class
.
':merge'
);
$app
->
delete
(
'/tags/{id}'
,
\Tag\controllers\TagController
::
class
.
':delete'
);
//Templates
...
...
This diff is collapsed.
Click to expand it.
src/app/tag/controllers/TagController.php
+
72
−
0
View file @
17d3784a
...
...
@@ -152,4 +152,76 @@ class TagController
return
$response
->
withStatus
(
204
);
}
public
function
merge
(
Request
$request
,
Response
$response
,
array
$args
)
{
if
(
!
ServiceModel
::
hasService
([
'id'
=>
'admin_tag'
,
'userId'
=>
$GLOBALS
[
'userId'
],
'location'
=>
'apps'
,
'type'
=>
'admin'
]))
{
return
$response
->
withStatus
(
403
)
->
withJson
([
'errors'
=>
'Service forbidden'
]);
}
$body
=
$request
->
getParsedBody
();
if
(
!
Validator
::
intVal
()
->
notEmpty
()
->
validate
(
$args
[
'id'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Route idMaster must be an integer val'
]);
}
$tagMaster
=
TagModel
::
getById
([
'id'
=>
$args
[
'id'
]]);
if
(
empty
(
$tagMaster
))
{
return
$response
->
withStatus
(
404
)
->
withJson
([
'errors'
=>
'Master tag not found'
]);
}
if
(
!
Validator
::
intVal
()
->
notEmpty
()
->
validate
(
$body
[
'idMerge'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Body idMerge must be an integer val'
]);
}
$tagMerge
=
TagModel
::
getById
([
'id'
=>
$body
[
'idMerge'
]]);
if
(
empty
(
$tagMerge
))
{
return
$response
->
withStatus
(
404
)
->
withJson
([
'errors'
=>
'Merge tag not found'
]);
}
$tagResMaster
=
TagModel
::
getTagRes
([
'where'
=>
[
'tag_id = ?'
],
'data'
=>
[
$tagMaster
[
'id'
]]
]);
$tagResMaster
=
array_column
(
$tagResMaster
,
'res_id'
);
TagModel
::
updateTagRes
([
'set'
=>
[
'tag_id'
=>
$tagMaster
[
'id'
]
],
'where'
=>
[
'tag_id = ?'
,
'res_id not in (?)'
],
'data'
=>
[
$tagMerge
[
'id'
],
$tagResMaster
]
]);
TagModel
::
deleteTagRes
([
'where'
=>
[
'tag_id = ?'
],
'data'
=>
[
$tagMerge
[
'id'
]]
]);
$tagResEntities
=
TagModel
::
getTagEntities
([
'where'
=>
[
'tag_id = ?'
],
'data'
=>
[
$tagMaster
[
'id'
]]
]);
$tagResEntities
=
array_column
(
$tagResEntities
,
'entity_id'
);
TagModel
::
updateTagEntities
([
'set'
=>
[
'tag_id'
=>
$tagMaster
[
'id'
]
],
'where'
=>
[
'tag_id = ?'
,
'entity_id not in (?)'
],
'data'
=>
[
$tagMerge
[
'id'
],
$tagResEntities
]
]);
TagModel
::
deleteTagEntities
([
'where'
=>
[
'tag_id = ?'
],
'data'
=>
[
$tagMerge
[
'id'
]]
]);
TagModel
::
delete
([
'where'
=>
[
'id = ?'
],
'data'
=>
[
$tagMerge
[
'id'
]]
]);
return
$response
->
withStatus
(
204
);
}
}
This diff is collapsed.
Click to expand it.
src/app/tag/models/TagModel.php
+
75
−
0
View file @
17d3784a
...
...
@@ -119,4 +119,79 @@ class TagModel
return
true
;
}
public
static
function
updateTagRes
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'where'
]);
ValidatorModel
::
arrayType
(
$args
,
[
'set'
,
'where'
,
'data'
]);
DatabaseModel
::
update
([
'table'
=>
'tag_res'
,
'set'
=>
empty
(
$args
[
'set'
])
?
[]
:
$args
[
'set'
],
'where'
=>
$args
[
'where'
],
'data'
=>
empty
(
$args
[
'data'
])
?
[]
:
$args
[
'data'
]
]);
return
true
;
}
public
static
function
deleteTagRes
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'where'
,
'data'
]);
ValidatorModel
::
arrayType
(
$args
,
[
'where'
,
'data'
]);
DatabaseModel
::
delete
([
'table'
=>
'tag_res'
,
'where'
=>
$args
[
'where'
],
'data'
=>
$args
[
'data'
]
]);
return
true
;
}
public
static
function
updateTagEntities
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'where'
]);
ValidatorModel
::
arrayType
(
$args
,
[
'set'
,
'where'
,
'data'
]);
DatabaseModel
::
update
([
'table'
=>
'tags_entities'
,
'set'
=>
empty
(
$args
[
'set'
])
?
[]
:
$args
[
'set'
],
'where'
=>
$args
[
'where'
],
'data'
=>
empty
(
$args
[
'data'
])
?
[]
:
$args
[
'data'
]
]);
return
true
;
}
public
static
function
deleteTagEntities
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'where'
,
'data'
]);
ValidatorModel
::
arrayType
(
$args
,
[
'where'
,
'data'
]);
DatabaseModel
::
delete
([
'table'
=>
'tags_entities'
,
'where'
=>
$args
[
'where'
],
'data'
=>
$args
[
'data'
]
]);
return
true
;
}
public
static
function
getTagEntities
(
array
$aArgs
)
{
ValidatorModel
::
arrayType
(
$aArgs
,
[
'select'
,
'where'
,
'data'
,
'orderBy'
]);
ValidatorModel
::
intType
(
$aArgs
,
[
'limit'
]);
$tags
=
DatabaseModel
::
select
([
'select'
=>
empty
(
$aArgs
[
'select'
])
?
[
'*'
]
:
$aArgs
[
'select'
],
'table'
=>
[
'tags_entities'
],
'where'
=>
empty
(
$aArgs
[
'where'
])
?
[]
:
$aArgs
[
'where'
],
'data'
=>
empty
(
$aArgs
[
'data'
])
?
[]
:
$aArgs
[
'data'
],
'order_by'
=>
empty
(
$aArgs
[
'orderBy'
])
?
[]
:
$aArgs
[
'orderBy'
],
'limit'
=>
empty
(
$aArgs
[
'limit'
])
?
0
:
$aArgs
[
'limit'
]
]);
return
$tags
;
}
}
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