Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
8caacbb9
Commit
8caacbb9
authored
2 years ago
by
Jan-Hendrik Willms
Committed by
David Siegfried
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
change execution order to ensure the id for storing i18n contents is valid, fixes #1990
Closes #1990 Merge request
studip/studip!1298
parent
b7bda469
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/models/SimpleORMap.class.php
+36
-52
36 additions, 52 deletions
lib/models/SimpleORMap.class.php
with
36 additions
and
52 deletions
lib/models/SimpleORMap.class.php
+
36
−
52
View file @
8caacbb9
...
...
@@ -330,13 +330,6 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
}
}
if
(
$config
[
'db_fields'
][
$config
[
'pk'
][
0
]][
'extra'
]
==
'auto_increment'
)
{
array_unshift
(
$config
[
'registered_callbacks'
][
'before_store'
],
'cbAutoIncrementColumn'
);
array_unshift
(
$config
[
'registered_callbacks'
][
'after_create'
],
'cbAutoIncrementColumn'
);
}
elseif
(
count
(
$config
[
'pk'
])
===
1
)
{
array_unshift
(
$config
[
'registered_callbacks'
][
'before_store'
],
'cbAutoKeyCreation'
);
}
$auto_notification_map
[
'after_create'
]
=
$class
.
'DidCreate'
;
$auto_notification_map
[
'after_store'
]
=
$class
.
'DidStore'
;
$auto_notification_map
[
'after_delete'
]
=
$class
.
'DidDelete'
;
...
...
@@ -1872,10 +1865,23 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
store
()
{
// Set id or prepare setting of id
if
(
$this
->
isNew
()
&&
$this
->
getId
()
===
null
)
{
// Explicitly set id to 0 if auto increment pk is null
if
(
$this
->
hasAutoIncrementColumn
())
{
$this
->
setId
(
0
);
}
else
{
$this
->
setId
(
$this
->
getNewId
());
}
}
if
(
$this
->
applyCallbacks
(
'before_store'
)
===
false
)
{
return
false
;
}
$ret
=
0
;
$i18ncontent
=
[];
if
(
!
$this
->
isDeleted
()
&&
(
$this
->
isDirty
()
||
$this
->
isNew
()))
{
if
(
$this
->
isNew
())
{
if
(
$this
->
applyCallbacks
(
'before_create'
)
===
false
)
{
...
...
@@ -1888,7 +1894,6 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
}
// Collect i18n contents
$i18ncontent
=
[];
foreach
(
array_keys
(
$this
->
i18n_fields
())
as
$field
)
{
if
(
$this
->
content
[
$field
]
instanceof
I18NString
)
{
$i18ncontent
[
$field
]
=
$this
->
content
[
$field
];
...
...
@@ -1931,30 +1936,37 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
}
$ret
=
DBManager
::
get
()
->
exec
(
$query
);
// Store i18n contents
if
(
count
(
$i18ncontent
)
>
0
)
{
foreach
(
$i18ncontent
as
$field
=>
$one
)
{
$meta
=
[
'object_id'
=>
$this
->
getId
(),
'table'
=>
$this
->
db_table
(),
'field'
=>
$field
];
$one
->
setMetadata
(
$meta
);
$one
->
storeTranslations
();
if
(
!
$this
->
content
[
$field
]
instanceof
I18NString
)
{
$this
->
content
[
$field
]
=
$one
;
$this
->
content_db
[
$field
]
=
clone
$one
;
}
}
}
if
(
$this
->
isNew
())
{
if
(
$this
->
hasAutoIncrementColumn
()
&&
!
$this
->
getId
())
{
$this
->
setId
(
DBManager
::
get
()
->
lastInsertId
());
}
$this
->
applyCallbacks
(
'after_create'
);
}
else
{
$this
->
applyCallbacks
(
'after_update'
);
}
}
$rel_ret
=
$this
->
storeRelations
();
// Store i18n contents
if
(
count
(
$i18ncontent
)
>
0
)
{
foreach
(
$i18ncontent
as
$field
=>
$one
)
{
$meta
=
[
'object_id'
=>
$this
->
getId
(),
'table'
=>
$this
->
db_table
(),
'field'
=>
$field
];
$one
->
setMetadata
(
$meta
);
$one
->
storeTranslations
();
if
(
!
$this
->
content
[
$field
]
instanceof
I18NString
)
{
$this
->
content
[
$field
]
=
$one
;
$this
->
content_db
[
$field
]
=
clone
$one
;
}
}
}
$this
->
applyCallbacks
(
'after_store'
);
if
(
$ret
||
$rel_ret
)
{
$this
->
restore
();
}
...
...
@@ -2344,34 +2356,6 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
return
$unreg
;
}
/**
* default callback for tables with auto_increment primary key
*
* @param string $type callback type
* @return boolean
*/
protected
function
cbAutoIncrementColumn
(
$type
)
{
if
(
$type
==
'after_create'
&&
!
$this
->
getId
())
{
$this
->
setId
(
DBManager
::
get
()
->
lastInsertId
());
}
if
(
$type
==
'before_store'
&&
$this
->
isNew
()
&&
$this
->
getId
()
===
null
)
{
$this
->
setId
(
0
);
}
return
true
;
}
/**
* default callback for tables without auto_increment
* @return void
*/
protected
function
cbAutoKeyCreation
()
{
if
(
$this
->
isNew
()
&&
$this
->
getId
()
===
null
)
{
$this
->
setId
(
$this
->
getNewId
());
}
}
/**
* default callback used to map specific callbacks to NotificationCenter
*
...
...
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