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
163c1aaa
Commit
163c1aaa
authored
Jul 17, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
3f84ede6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
102 deletions
+24
-102
AuditLog.php
lib/Doctrine/AuditLog.php
+22
-101
Listener.php
lib/Doctrine/AuditLog/Listener.php
+2
-1
No files found.
lib/Doctrine/AuditLog.php
View file @
163c1aaa
...
...
@@ -33,20 +33,16 @@ class Doctrine_AuditLog
{
protected
$_options
=
array
(
'className'
=>
'%CLASS%Version'
,
'deleteTrigger'
=>
'%TABLE%_ddtr'
,
'updateTrigger'
=>
'%TABLE%_dutr'
,
'versionTable'
=>
'%TABLE%_dvt'
,
'versionColumn'
=>
'version'
,
'generateFiles'
=>
false
,
'table'
=>
null
,
);
protected
$_table
;
protected
$_auditTable
;
public
function
__construct
(
Doctrine_Table
$table
)
public
function
__construct
(
$options
)
{
$this
->
_table
=
$table
;
$this
->
_options
=
array_merge
(
$this
->
_options
,
$options
);
}
/**
* __get
...
...
@@ -111,25 +107,7 @@ class Doctrine_AuditLog
}
return
null
;
}
public
function
audit
()
{
$conn
=
$this
->
_table
->
getConnection
();
// begin new transaction
$conn
->
beginTransaction
();
try
{
// create the version table and the triggers
$this
->
createVersionTable
();
$conn
->
execute
(
$this
->
deleteTriggerSql
());
$conn
->
execute
(
$this
->
updateTriggerSql
());
// commit structure changes
$conn
->
commit
();
}
catch
(
Doctrine_Connection_Exception
$e
)
{
$conn
->
rollback
();
}
}
public
function
getVersion
(
Doctrine_Record
$record
,
$version
)
{
$className
=
str_replace
(
'%CLASS%'
,
$this
->
_table
->
getComponentName
(),
$this
->
_options
[
'className'
]);
...
...
@@ -149,88 +127,31 @@ class Doctrine_AuditLog
->
where
(
$where
)
->
execute
(
$values
,
Doctrine_HYDRATE
::
HYDRATE_ARRAY
);
}
public
function
createVersionTable
(
)
public
function
buildDefinition
(
Doctrine_Table
$table
)
{
$data
=
$this
->
_table
->
getExportableFormat
(
false
);
$conn
=
$this
->
_table
->
getConnection
();
$data
[
'tableName'
]
=
str_replace
(
'%TABLE%'
,
$data
[
'tableName'
],
$this
->
_options
[
'versionTable'
]);
foreach
(
$data
[
'columns'
]
as
$name
=>
$def
)
{
unset
(
$data
[
'columns'
][
$name
][
'autoinc'
]);
unset
(
$data
[
'columns'
][
$name
][
'autoincrement'
]);
unset
(
$data
[
'columns'
][
$name
][
'sequence'
]);
unset
(
$data
[
'columns'
][
$name
][
'seq'
]);
}
$data
[
'columns'
][
$this
->
_options
[
'versionColumn'
]][
'primary'
]
=
true
;
$name
=
$table
->
getComponentName
();
$className
=
str_replace
(
'%CLASS%'
,
$this
->
_table
->
getComponentName
(),
$this
->
_options
[
'className'
]);
$definition
=
'class '
.
$className
.
' extends Doctrine_Record { '
.
'public function setTableDefinition() { '
.
'$this->hasColumns('
.
var_export
(
$data
[
'columns'
],
true
)
.
');'
.
'$this->option(\'tableName\', \''
.
$data
[
'tableName'
]
.
'\'); } }'
;
$className
=
$name
.
'Version'
;
$this
->
_table
->
getRelationParser
()
->
bind
(
$className
,
array
(
'local'
=>
$this
->
_table
->
getIdentifier
(),
'foreign'
=>
$this
->
_table
->
getIdentifier
(),
'type'
=>
Doctrine_Relation
::
MANY
));
if
(
class_exists
(
$className
))
{
return
false
;
}
$columns
=
$table
->
getColumns
();
$
this
->
_table
->
addListener
(
new
Doctrine_AuditLog_Listener
(
$this
)
);
$
id
=
$table
->
getIdentifier
(
);
eval
(
$definition
);
$options
=
array
(
'className'
=>
$className
);
$
data
[
'options'
][
'primary'
][]
=
$this
->
_options
[
'versionColumn'
]
;
$
builder
=
new
Doctrine_Import_Builder
()
;
$options
[
'primary'
][]
=
$this
->
_options
[
'versionColumn'
];
$this
->
_auditTable
=
$this
->
_table
->
getConnection
()
->
getTable
(
$className
);
}
/**
* deleteTriggerSql
*
* returns the sql needed for the delete trigger creation
*/
public
function
deleteTriggerSql
()
{
$conn
=
$this
->
_table
->
getConnection
();
$columnNames
=
$this
->
_table
->
getColumnNames
();
$oldColumns
=
array_map
(
array
(
$this
,
'formatOld'
),
$columnNames
);
$sql
=
'CREATE TRIGGER '
.
$conn
->
quoteIdentifier
(
$this
->
_table
->
getTableName
())
.
'_ddt'
.
' BEFORE DELETE ON '
.
$conn
->
quoteIdentifier
(
$this
->
_table
->
getTableName
())
.
' BEGIN'
.
' INSERT INTO '
.
$this
->
_table
->
getTableName
()
.
'_dvt ('
.
implode
(
', '
,
array_map
(
array
(
$conn
,
'quoteIdentifier'
),
$columnNames
))
.
') VALUES ('
.
implode
(
', '
,
array_map
(
array
(
$conn
,
'quoteIdentifier'
),
$oldColumns
))
.
');'
.
' END;'
;
return
$sql
;
}
/**
* updateTriggerSql
*
* returns the sql needed for the update trigger creation
*/
public
function
updateTriggerSql
()
{
$conn
=
$this
->
_table
->
getConnection
();
$columnNames
=
$this
->
_table
->
getColumnNames
();
$oldColumns
=
array_map
(
array
(
$this
,
'formatOld'
),
$columnNames
);
$sql
=
'CREATE TRIGGER '
.
$conn
->
quoteIdentifier
(
$this
->
_table
->
getTableName
())
.
'_dut'
.
' UPDATE ON '
.
$conn
->
quoteIdentifier
(
$this
->
_table
->
getTableName
())
.
' BEGIN'
.
' INSERT INTO '
.
$this
->
_table
->
getTableName
()
.
'_dvt ('
.
implode
(
', '
,
array_map
(
array
(
$conn
,
'quoteIdentifier'
),
$columnNames
))
.
') VALUES ('
.
implode
(
', '
,
array_map
(
array
(
$conn
,
'quoteIdentifier'
),
$oldColumns
))
.
');'
.
' END;'
;
return
$sql
;
$def
=
$builder
->
buildDefinition
(
$options
,
$columns
);
if
(
!
$this
->
_options
[
'generateFiles'
])
{
eval
(
$def
);
}
public
function
formatOld
(
$column
)
{
return
'old.'
.
$column
;
return
true
;
}
}
lib/Doctrine/AuditLog/Listener.php
View file @
163c1aaa
...
...
@@ -18,6 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Record_Listener'
);
/**
* Doctrine_AuditLog_Listener
*
...
...
@@ -29,7 +30,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_AuditLog_Listener
extends
Doctrine_
Event
Listener
class
Doctrine_AuditLog_Listener
extends
Doctrine_
Record_
Listener
{
protected
$_auditLog
;
...
...
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