Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
ab1f1de9
Commit
ab1f1de9
authored
Jun 24, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
0d5b4493
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
87 deletions
+110
-87
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+92
-87
Event.php
lib/Doctrine/Event.php
+18
-0
No files found.
lib/Doctrine/Connection/UnitOfWork.php
View file @
ab1f1de9
...
...
@@ -145,20 +145,22 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record
->
preSave
(
$event
);
switch
(
$record
->
state
())
{
case
Doctrine_Record
::
STATE_TDIRTY
:
$this
->
insert
(
$record
);
break
;
case
Doctrine_Record
::
STATE_DIRTY
:
case
Doctrine_Record
::
STATE_PROXY
:
$this
->
update
(
$record
);
break
;
case
Doctrine_Record
::
STATE_CLEAN
:
case
Doctrine_Record
::
STATE_TCLEAN
:
// do nothing
break
;
if
(
!
$event
->
getSkipOperation
())
{
switch
(
$record
->
state
())
{
case
Doctrine_Record
::
STATE_TDIRTY
:
$this
->
insert
(
$record
);
break
;
case
Doctrine_Record
::
STATE_DIRTY
:
case
Doctrine_Record
::
STATE_PROXY
:
$this
->
update
(
$record
);
break
;
case
Doctrine_Record
::
STATE_CLEAN
:
case
Doctrine_Record
::
STATE_TCLEAN
:
// do nothing
break
;
}
}
$record
->
postSave
(
$event
);
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onSave
(
$record
);
...
...
@@ -186,13 +188,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$this
->
deleteComposites
(
$record
);
$this
->
conn
->
transaction
->
addDelete
(
$record
);
$record
->
postDelete
(
$event
);
if
(
!
$event
->
getSkipOperation
())
{
$this
->
conn
->
transaction
->
addDelete
(
$record
);
$record
->
state
(
Doctrine_Record
::
STATE_TCLEAN
);
}
$record
->
getTable
()
->
getListener
()
->
onDelete
(
$record
);
$record
->
state
(
Doctrine_Record
::
STATE_TCLEAN
);
$record
->
postDelete
(
$event
);
$this
->
conn
->
commit
();
...
...
@@ -337,43 +340,44 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record
->
preUpdate
(
$event
);
$array
=
$record
->
getPrepared
();
if
(
empty
(
$array
))
{
return
false
;
}
$set
=
array
();
foreach
(
$array
as
$name
=>
$value
)
{
$set
[]
=
$name
.
' = ?'
;
if
(
$value
instanceof
Doctrine_Record
)
{
if
(
!
$value
->
exists
())
{
$record
->
save
(
$this
->
conn
);
if
(
!
$event
->
getSkipOperation
())
{
$array
=
$record
->
getPrepared
();
if
(
empty
(
$array
))
{
return
false
;
}
$set
=
array
();
foreach
(
$array
as
$name
=>
$value
)
{
$set
[]
=
$name
.
' = ?'
;
if
(
$value
instanceof
Doctrine_Record
)
{
if
(
!
$value
->
exists
())
{
$record
->
save
(
$this
->
conn
);
}
$array
[
$name
]
=
$value
->
getIncremented
();
$record
->
set
(
$name
,
$value
->
getIncremented
());
}
$array
[
$name
]
=
$value
->
getIncremented
();
$record
->
set
(
$name
,
$value
->
getIncremented
());
}
$params
=
array_values
(
$array
);
$id
=
$record
->
obtainIdentifier
();
if
(
!
is_array
(
$id
))
{
$id
=
array
(
$id
);
}
$id
=
array_values
(
$id
);
$params
=
array_merge
(
$params
,
$id
);
$sql
=
'UPDATE '
.
$this
->
conn
->
quoteIdentifier
(
$record
->
getTable
()
->
getTableName
())
.
' SET '
.
implode
(
', '
,
$set
)
.
' WHERE '
.
implode
(
' = ? AND '
,
$record
->
getTable
()
->
getPrimaryKeys
())
.
' = ?'
;
$stmt
=
$this
->
conn
->
getDbh
()
->
prepare
(
$sql
);
$stmt
->
execute
(
$params
);
$record
->
assignIdentifier
(
true
);
}
$params
=
array_values
(
$array
);
$id
=
$record
->
obtainIdentifier
();
if
(
!
is_array
(
$id
))
{
$id
=
array
(
$id
);
}
$id
=
array_values
(
$id
);
$params
=
array_merge
(
$params
,
$id
);
$sql
=
'UPDATE '
.
$this
->
conn
->
quoteIdentifier
(
$record
->
getTable
()
->
getTableName
())
.
' SET '
.
implode
(
', '
,
$set
)
.
' WHERE '
.
implode
(
' = ? AND '
,
$record
->
getTable
()
->
getPrimaryKeys
())
.
' = ?'
;
$stmt
=
$this
->
conn
->
getDbh
()
->
prepare
(
$sql
);
$stmt
->
execute
(
$params
);
$record
->
assignIdentifier
(
true
);
$record
->
postUpdate
(
$event
);
$record
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onUpdate
(
$record
);
...
...
@@ -394,45 +398,46 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$event
=
new
Doctrine_Event
(
$this
,
Doctrine_Event
::
INSERT
);
$record
->
preInsert
(
$event
);
$array
=
$record
->
getPrepared
();
if
(
empty
(
$array
))
{
return
false
;
}
$table
=
$record
->
getTable
();
$keys
=
$table
->
getPrimaryKeys
();
$seq
=
$record
->
getTable
()
->
sequenceName
;
if
(
!
empty
(
$seq
))
{
$id
=
$this
->
conn
->
sequence
->
nextId
(
$seq
);
$name
=
$record
->
getTable
()
->
getIdentifier
();
$array
[
$name
]
=
$id
;
$record
->
assignIdentifier
(
$id
);
}
$this
->
conn
->
insert
(
$table
->
getTableName
(),
$array
);
if
(
empty
(
$seq
)
&&
count
(
$keys
)
==
1
&&
$keys
[
0
]
==
$table
->
getIdentifier
()
&&
$table
->
getIdentifierType
()
!=
Doctrine_Identifier
::
NORMAL
)
{
if
(
strtolower
(
$this
->
conn
->
getName
())
==
'pgsql'
)
{
$seq
=
$table
->
getTableName
()
.
'_'
.
$keys
[
0
];
if
(
!
$event
->
getSkipOperation
())
{
$array
=
$record
->
getPrepared
();
if
(
empty
(
$array
))
{
return
false
;
}
$id
=
$this
->
conn
->
sequence
->
lastInsertId
(
$seq
);
if
(
!
$id
)
{
$id
=
$table
->
getMaxIdentifier
();
$table
=
$record
->
getTable
();
$keys
=
$table
->
getPrimaryKeys
();
$seq
=
$record
->
getTable
()
->
sequenceName
;
if
(
!
empty
(
$seq
))
{
$id
=
$this
->
conn
->
sequence
->
nextId
(
$seq
);
$name
=
$record
->
getTable
()
->
getIdentifier
();
$array
[
$name
]
=
$id
;
$record
->
assignIdentifier
(
$id
);
}
$this
->
conn
->
insert
(
$table
->
getTableName
(),
$array
);
if
(
empty
(
$seq
)
&&
count
(
$keys
)
==
1
&&
$keys
[
0
]
==
$table
->
getIdentifier
()
&&
$table
->
getIdentifierType
()
!=
Doctrine_Identifier
::
NORMAL
)
{
if
(
strtolower
(
$this
->
conn
->
getName
())
==
'pgsql'
)
{
$seq
=
$table
->
getTableName
()
.
'_'
.
$keys
[
0
];
}
$id
=
$this
->
conn
->
sequence
->
lastInsertId
(
$seq
);
if
(
!
$id
)
{
$id
=
$table
->
getMaxIdentifier
();
}
$record
->
assignIdentifier
(
$id
);
}
else
{
$record
->
assignIdentifier
(
true
);
}
$record
->
assignIdentifier
(
$id
);
}
else
{
$record
->
assignIdentifier
(
true
);
}
$record
->
postInsert
(
$event
);
// listen the onInsert event
...
...
lib/Doctrine/Event.php
View file @
ab1f1de9
...
...
@@ -137,6 +137,24 @@ class Doctrine_Event
{
return
$this
->
_code
;
}
/**
* setSkipOperation
*
* @return void
*/
public
function
setSkipOperation
(
$bool
)
{
$this
->
_skipOperation
=
(
bool
)
$bool
;
}
/**
* getSkipOperation
*
* @return void
*/
public
function
getSkipOperation
()
{
return
$this
->
_skipOperation
;
}
/**
* start
* starts the internal timer of this event
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment