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
2bd70e67
Commit
2bd70e67
authored
2 years ago
by
Jean-Laurent DUZANT
Browse files
Options
Downloads
Patches
Plain Diff
FIX #19580 TIME 4:30 add new sql function to create dynamic Sequence to return a chrono id
parent
7855dba5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sql/structure.sql
+11
-0
11 additions, 0 deletions
sql/structure.sql
src/app/resource/models/ChronoModel.php
+7
-39
7 additions, 39 deletions
src/app/resource/models/ChronoModel.php
src/core/models/DatabaseModel.php
+20
-0
20 additions, 0 deletions
src/core/models/DatabaseModel.php
with
38 additions
and
39 deletions
sql/structure.sql
+
11
−
0
View file @
2bd70e67
...
...
@@ -1558,3 +1558,14 @@ CREATE TABLE address_sectors
CONSTRAINT
address_sectors_pkey
PRIMARY
KEY
(
id
)
)
WITH
(
OIDS
=
FALSE
);
CREATE
OR
REPLACE
FUNCTION
public
.
increase_chrono
(
chrono_id_seq
text
)
returns
table
(
chrono_id
bigint
)
as
$$
DECLARE
retval
bigint
;
BEGIN
IF
NOT
EXISTS
(
SELECT
0
FROM
pg_class
where
relname
=
chrono_id_seq
)
THEN
EXECUTE
'CREATE SEQUENCE '
||
chrono_id_seq
||
' INCREMENT 1 MINVALUE 100 MAXVALUE 9223372036854775807 START 100 CACHE 1;'
;
END
IF
;
RETURN
QUERY
EXECUTE
'SELECT nextval($1)'
USING
chrono_id_seq
;
END
;
$$
LANGUAGE
plpgsql
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/app/resource/models/ChronoModel.php
+
7
−
39
View file @
2bd70e67
...
...
@@ -17,6 +17,7 @@ namespace Resource\models;
use
Parameter\models\ParameterModel
;
use
SrcCore\models\ValidatorModel
;
use
SrcCore\models\CoreConfigModel
;
use
SrcCore\models\DatabaseModel
;
class
ChronoModel
{
...
...
@@ -86,19 +87,8 @@ class ChronoModel
*/
public
static
function
getChronoGlobal
()
{
$chronoId
=
'chrono_global_'
.
date
(
'Y'
);
$parameter
=
ParameterModel
::
getById
([
'id'
=>
$chronoId
,
'select'
=>
[
'param_value_int'
]]);
if
(
empty
(
$parameter
))
{
ParameterModel
::
create
([
'id'
=>
$chronoId
,
'param_value_int'
=>
1
]);
$chrono
=
1
;
}
else
{
$chrono
=
$parameter
[
'param_value_int'
];
}
ParameterModel
::
update
([
'id'
=>
$chronoId
,
'param_value_int'
=>
$chrono
+
1
]);
$chronoId
=
'chrono_global_'
.
date
(
'Y'
)
.
"_seq"
;
$chrono
=
DatabaseModel
::
createOrIncreaseChrono
([
'chronoId'
=>
$chronoId
]);
return
$chrono
;
}
...
...
@@ -107,37 +97,15 @@ class ChronoModel
*/
public
static
function
getChronoEntity
(
$entityId
)
{
$chronoId
=
"chrono_
{
$entityId
}
_"
.
date
(
'Y'
);
$parameter
=
ParameterModel
::
getById
([
'id'
=>
$chronoId
,
'select'
=>
[
'param_value_int'
]]);
if
(
empty
(
$parameter
))
{
ParameterModel
::
create
([
'id'
=>
$chronoId
,
'param_value_int'
=>
1
]);
$chrono
=
1
;
}
else
{
$chrono
=
$parameter
[
'param_value_int'
];
}
ParameterModel
::
update
([
'id'
=>
$chronoId
,
'param_value_int'
=>
$chrono
+
1
]);
$chronoId
=
"chrono_
{
$entityId
}
_"
.
date
(
'Y'
)
.
"_seq"
;
$chrono
=
DatabaseModel
::
createOrIncreaseChrono
([
'chronoId'
=>
$chronoId
]);
return
$entityId
.
"/"
.
$chrono
;
}
public
static
function
getChronoCategory
(
$categoryId
)
{
$chronoId
=
"chrono_
{
$categoryId
}
_"
.
date
(
'Y'
);
$parameter
=
ParameterModel
::
getById
([
'id'
=>
$chronoId
,
'select'
=>
[
'param_value_int'
]]);
if
(
empty
(
$parameter
))
{
ParameterModel
::
create
([
'id'
=>
$chronoId
,
'param_value_int'
=>
1
]);
$chrono
=
1
;
}
else
{
$chrono
=
$parameter
[
'param_value_int'
];
}
ParameterModel
::
update
([
'id'
=>
$chronoId
,
'param_value_int'
=>
$chrono
+
1
]);
$chronoId
=
"chrono_
{
$categoryId
}
_"
.
date
(
'Y'
)
.
"_seq"
;
$chrono
=
DatabaseModel
::
createOrIncreaseChrono
([
'chronoId'
=>
$chronoId
]);
return
"/"
.
$chrono
;
}
...
...
This diff is collapsed.
Click to expand it.
src/core/models/DatabaseModel.php
+
20
−
0
View file @
2bd70e67
...
...
@@ -16,6 +16,26 @@ namespace SrcCore\models;
class
DatabaseModel
{
/**
* Database increase_chrono function
* @param array $args
*
* @return int
* @throws \Exception
*/
public
static
function
createOrIncreaseChrono
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'chronoId'
]);
ValidatorModel
::
stringType
(
$args
,
[
'chronoId'
]);
$query
=
"SELECT increase_chrono('
{
$args
[
'chronoId'
]
}
')"
;
$db
=
new
DatabasePDO
();
$stmt
=
$db
->
query
(
$query
);
$row
=
$stmt
->
fetch
(
\PDO
::
FETCH_ASSOC
);
return
$row
[
'increase_chrono'
];
}
/**
* Database Nextval Sequence Function
* @param array $args
...
...
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