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
a5f755f4
Commit
a5f755f4
authored
Nov 27, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enhanced plugin initialization procedure
parent
206002de
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
113 additions
and
118 deletions
+113
-118
AuditLog.php
lib/Doctrine/AuditLog.php
+4
-14
Listener.php
lib/Doctrine/AuditLog/Listener.php
+6
-2
Export.php
lib/Doctrine/Export.php
+3
-5
I18n.php
lib/Doctrine/I18n.php
+13
-25
Plugin.php
lib/Doctrine/Plugin.php
+70
-25
Search.php
lib/Doctrine/Search.php
+8
-25
File.php
lib/Doctrine/Search/File.php
+5
-1
I18n.php
lib/Doctrine/Template/I18n.php
+2
-10
Searchable.php
lib/Doctrine/Template/Searchable.php
+1
-10
Versionable.php
lib/Doctrine/Template/Versionable.php
+1
-1
No files found.
lib/Doctrine/AuditLog.php
View file @
a5f755f4
...
...
@@ -86,7 +86,7 @@ class Doctrine_AuditLog extends Doctrine_Plugin
* @param Doctrine_Table $table
* @return boolean true on success otherwise false.
*/
public
function
build
Definition
()
public
function
setTable
Definition
()
{
$name
=
$this
->
_options
[
'table'
]
->
getComponentName
();
...
...
@@ -99,19 +99,9 @@ class Doctrine_AuditLog extends Doctrine_Plugin
unset
(
$columns
[
$column
][
'unique'
]);
}
// the version column should be part of the primary key definition
$columns
[
$this
->
_options
[
'versionColumn'
]]
=
array
(
'type'
=>
'integer'
,
'length'
=>
8
,
'primary'
=>
true
);
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$relations
=
$this
->
buildRelation
();
$this
->
hasColumns
(
$columns
);
$this
->
generateClass
(
$columns
,
$relations
);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
return
true
;
// the version column should be part of the primary key definition
$this
->
hasColumn
(
$this
->
_options
[
'versionColumn'
],
'integer'
,
8
,
array
(
'primary'
=>
true
));
}
}
lib/Doctrine/AuditLog/Listener.php
View file @
a5f755f4
...
...
@@ -35,25 +35,28 @@ class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
protected
$_auditLog
;
public
function
__construct
(
Doctrine_AuditLog
$auditLog
)
{
public
function
__construct
(
Doctrine_AuditLog
$auditLog
)
{
$this
->
_auditLog
=
$auditLog
;
}
public
function
preInsert
(
Doctrine_Event
$event
)
{
$versionColumn
=
$this
->
_auditLog
->
getOption
(
'versionColumn'
);
$event
->
getInvoker
()
->
set
(
$versionColumn
,
1
);
}
public
function
postInsert
(
Doctrine_Event
$event
)
{
$class
=
$this
->
_auditLog
->
getOption
(
'className'
);
$record
=
$event
->
getInvoker
();
$version
=
new
$class
();
$version
->
merge
(
$record
->
toArray
());
$version
->
save
();
}
public
function
preDelete
(
Doctrine_Event
$event
)
{
$class
=
$this
->
_auditLog
->
getOption
(
'className'
);
...
...
@@ -69,6 +72,7 @@ class Doctrine_AuditLog_Listener extends Doctrine_Record_Listener
$version
->
merge
(
$record
->
toArray
());
$version
->
save
();
}
public
function
preUpdate
(
Doctrine_Event
$event
)
{
$class
=
$this
->
_auditLog
->
getOption
(
'className'
);
...
...
lib/Doctrine/Export.php
View file @
a5f755f4
...
...
@@ -1174,16 +1174,14 @@ class Doctrine_Export extends Doctrine_Connection_Module
{
$plugins
=
array
();
foreach
(
$table
->
getTemplates
()
as
$name
=>
$template
)
{
$plugin
=
$template
->
getPlugin
();
foreach
(
$table
->
getPlugins
()
as
$name
=>
$plugin
)
{
if
(
$plugin
===
null
)
{
continue
;
}
$plugins
[]
=
$plugin
;
$pluginTable
=
$plugin
->
get
Option
(
'pluginTable'
);
$pluginTable
=
$plugin
->
get
Table
(
);
if
(
$pluginTable
instanceof
Doctrine_Table
)
{
$plugins
=
array_merge
(
$plugins
,
$this
->
getAllPlugins
(
$pluginTable
));
...
...
@@ -1205,7 +1203,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$sql
=
array
();
foreach
(
$this
->
getAllPlugins
(
$table
)
as
$name
=>
$plugin
)
{
$table
=
$plugin
->
get
Option
(
'pluginTable'
);
$table
=
$plugin
->
get
Table
(
);
// Make sure plugin has a valid table
if
(
$table
instanceof
Doctrine_Table
)
{
...
...
lib/Doctrine/I18n.php
View file @
a5f755f4
...
...
@@ -52,26 +52,26 @@ class Doctrine_I18n extends Doctrine_Plugin
$this
->
_options
=
array_merge
(
$this
->
_options
,
$options
);
}
public
function
buildRelation
()
{
$this
->
buildForeignRelation
(
'Translation'
);
$this
->
buildLocalRelation
();
}
/**
* buildDefinition
*
* @param object $Doctrine_Table
* @return void
*/
public
function
build
Definition
()
public
function
setTable
Definition
()
{
if
(
empty
(
$this
->
_options
[
'fields'
]))
{
throw
new
Doctrine_I18n_Exception
(
'Fields not set.'
);
}
$name
=
$this
->
_options
[
'table'
]
->
getComponentName
();
$columns
=
array
();
$options
=
array
(
'className'
=>
$this
->
_options
[
'className'
]);
$fk
=
$this
->
buildForeignKeys
(
$this
->
_options
[
'table'
]);
$cols
=
$this
->
_options
[
'table'
]
->
getColumns
();
foreach
(
$cols
as
$column
=>
$definition
)
{
...
...
@@ -81,23 +81,11 @@ class Doctrine_I18n extends Doctrine_Plugin
}
}
$columns
[
'lang'
]
=
array
(
'type'
=>
'string'
,
'length'
=>
2
,
'fixed'
=>
true
,
'primary'
=>
true
);
$relations
=
$this
->
buildRelation
();
$columns
+=
$fk
;
$options
=
array
(
'queryParts'
=>
array
(
'indexBy'
=>
'lang'
));
$this
->
generateClass
(
$columns
,
$relations
,
$options
);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'table'
]
->
getConnection
()
->
getTable
(
$this
->
_options
[
'className'
]);
$this
->
hasColumns
(
$columns
);
$this
->
_options
[
'pluginTable'
]
->
bindQueryPart
(
'indexBy'
,
'lang'
);
$this
->
hasColumn
(
'lang'
,
'string'
,
2
,
array
(
'fixed'
=>
true
,
'primary'
=>
true
));
return
true
;
$this
->
bindQueryParts
(
array
(
'indexBy'
=>
'lang'
))
;
}
}
lib/Doctrine/Plugin.php
View file @
a5f755f4
...
...
@@ -30,7 +30,7 @@
* @link www.phpdoctrine.com
* @since 1.0
*/
abstract
class
Doctrine_Plugin
abstract
class
Doctrine_Plugin
extends
Doctrine_Record_Abstract
{
/**
* @var array $_options an array of plugin specific options
...
...
@@ -42,6 +42,7 @@ abstract class Doctrine_Plugin
'pluginTable'
=>
false
,
'children'
=>
array
());
protected
$_initialized
=
false
;
/**
* __get
* an alias for getOption
...
...
@@ -110,10 +111,18 @@ abstract class Doctrine_Plugin
return
$this
->
_options
;
}
public
function
buildPluginDefinition
(
Doctrine_Table
$table
)
public
function
initialize
(
Doctrine_Table
$table
)
{
if
(
$this
->
_initialized
)
{
return
false
;
}
$this
->
_initialized
=
true
;
$this
->
initOptions
();
$table
->
addPlugin
(
$this
,
get_class
(
$this
));
$this
->
_options
[
'table'
]
=
$table
;
$this
->
_options
[
'className'
]
=
str_replace
(
'%CLASS%'
,
...
...
@@ -125,9 +134,25 @@ abstract class Doctrine_Plugin
return
false
;
}
$this
->
buildDefinition
();
$conn
=
$this
->
_options
[
'table'
]
->
getConnection
();
$this
->
_table
=
new
Doctrine_Table
(
$this
->
_options
[
'className'
],
$conn
);
$conn
->
addTable
(
$this
->
_table
);
$fk
=
$this
->
buildForeignKeys
(
$this
->
_options
[
'table'
]);
$this
->
_table
->
setColumns
(
$fk
);
$this
->
buildRelation
();
$this
->
setTableDefinition
();
$this
->
setUp
();
$this
->
generateClass
(
$this
->
_table
->
getColumns
());
$this
->
buildChildDefinitions
();
}
/**
* empty template method for providing the concrete plugins the ability
...
...
@@ -139,20 +164,16 @@ abstract class Doctrine_Plugin
{
}
abstract
public
function
buildDefinition
();
public
function
buildChildDefinitions
()
{
if
(
!
isset
(
$this
->
_options
[
'children'
]))
{
Doctrine
::
dump
(
debug_backtrace
());
throw
new
Doctrine_Plugin_Exception
(
"Unknown option 'children'."
);
}
foreach
(
$this
->
_options
[
'children'
]
as
$child
)
{
$this
->
_
options
[
'pluginTable'
]
->
addTemplate
(
get_class
(
$child
),
$child
);
$this
->
_
table
->
addTemplate
(
get_class
(
$child
),
$child
);
$child
->
setTable
(
$this
->
_
options
[
'pluginTable'
]
);
$child
->
setTable
(
$this
->
_
table
);
$child
->
setUp
();
}
...
...
@@ -186,6 +207,35 @@ abstract class Doctrine_Plugin
return
$fk
;
}
public
function
buildLocalRelation
()
{
$options
=
array
(
'local'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'type'
=>
Doctrine_Relation
::
MANY
);
$options
[
'type'
]
=
Doctrine_Relation
::
ONE
;
$options
[
'onDelete'
]
=
'CASCADE'
;
$options
[
'onUpdate'
]
=
'CASCADE'
;
$this
->
_table
->
getRelationParser
()
->
bind
(
$this
->
_options
[
'table'
]
->
getComponentName
(),
$options
);
}
public
function
buildForeignRelation
(
$alias
=
null
)
{
$options
=
array
(
'local'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'type'
=>
Doctrine_Relation
::
MANY
);
$aliasStr
=
''
;
if
(
$alias
!==
null
)
{
$aliasStr
=
' as '
.
$alias
;
}
$this
->
_options
[
'table'
]
->
getRelationParser
()
->
bind
(
$this
->
_table
->
getComponentName
()
.
$aliasStr
,
$options
);
}
/**
* build a relation array to given table
*
...
...
@@ -196,13 +246,8 @@ abstract class Doctrine_Plugin
*/
public
function
buildRelation
()
{
$relation
=
array
(
$this
->
_options
[
'table'
]
->
getComponentName
()
=>
array
(
'local'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'foreign'
=>
$this
->
_options
[
'table'
]
->
getIdentifier
(),
'onDelete'
=>
'CASCADE'
,
'onUpdate'
=>
'CASCADE'
));
return
$relation
;
$this
->
buildForeignRelation
();
$this
->
buildLocalRelation
();
}
/**
...
...
lib/Doctrine/Search.php
View file @
a5f755f4
...
...
@@ -73,7 +73,7 @@ class Doctrine_Search extends Doctrine_Plugin
*/
public
function
search
(
$query
)
{
$q
=
new
Doctrine_Search_Query
(
$this
->
_
options
[
'pluginTable'
]
);
$q
=
new
Doctrine_Search_Query
(
$this
->
_
table
);
$q
->
query
(
$query
);
...
...
@@ -100,7 +100,7 @@ class Doctrine_Search extends Doctrine_Plugin
*/
public
function
updateIndex
(
array
$data
)
{
$this
->
buildDefinition
();
$this
->
initialize
(
$this
->
_options
[
'table'
]);
$fields
=
$this
->
getOption
(
'fields'
);
$class
=
$this
->
getOption
(
'className'
);
...
...
@@ -155,7 +155,7 @@ class Doctrine_Search extends Doctrine_Plugin
*/
public
function
readTableData
(
$limit
=
null
,
$offset
=
null
)
{
$this
->
buildDefinition
();
$this
->
initialize
(
$this
->
_options
[
'table'
]);
$conn
=
$this
->
_options
[
'table'
]
->
getConnection
();
$tableName
=
$this
->
_options
[
'table'
]
->
getTableName
();
...
...
@@ -164,7 +164,7 @@ class Doctrine_Search extends Doctrine_Plugin
$query
=
'SELECT * FROM '
.
$conn
->
quoteIdentifier
(
$tableName
)
.
' WHERE '
.
$conn
->
quoteIdentifier
(
$id
)
.
' IN (SELECT '
.
$conn
->
quoteIdentifier
(
$id
)
.
' FROM '
.
$conn
->
quoteIdentifier
(
$this
->
_
options
[
'pluginTable'
]
->
getTableName
())
.
' FROM '
.
$conn
->
quoteIdentifier
(
$this
->
_
table
->
getTableName
())
.
' WHERE keyword IS NULL)'
;
$query
=
$conn
->
modifyLimitQuery
(
$query
,
$limit
,
$offset
);
...
...
@@ -183,7 +183,7 @@ class Doctrine_Search extends Doctrine_Plugin
*/
public
function
batchUpdateIndex
(
$limit
=
null
,
$offset
=
null
)
{
$this
->
buildDefinition
(
);
$this
->
initialize
(
$this
->
_options
[
'table'
]
);
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$class
=
$this
->
_options
[
'className'
];
...
...
@@ -200,7 +200,7 @@ class Doctrine_Search extends Doctrine_Plugin
}
$conn
->
exec
(
'DELETE FROM '
.
$conn
->
quoteIdentifier
(
$this
->
_
options
[
'pluginTable'
]
->
getTableName
())
.
$conn
->
quoteIdentifier
(
$this
->
_
table
->
getTableName
())
.
' WHERE '
.
$conn
->
quoteIdentifier
(
$id
)
.
' IN ('
.
implode
(
', '
,
$ids
)
.
')'
);
foreach
(
$rows
as
$row
)
{
...
...
@@ -236,10 +236,9 @@ class Doctrine_Search extends Doctrine_Plugin
*
* @return void
*/
public
function
build
Definition
()
public
function
setTable
Definition
()
{
if
(
!
isset
(
$this
->
_options
[
'table'
]))
{
Doctrine
::
dump
(
debug_backtrace
());
throw
new
Doctrine_Plugin_Exception
(
"Unknown option 'table'."
);
}
...
...
@@ -263,22 +262,6 @@ class Doctrine_Search extends Doctrine_Plugin
'primary'
=>
true
,
));
$id
=
$this
->
_options
[
'table'
]
->
getIdentifier
();
$fk
=
$this
->
buildForeignKeys
(
$this
->
_options
[
'table'
]);
$columns
+=
$fk
;
$relations
=
array
();
// only generate relations for database based searches
if
(
!
$this
instanceof
Doctrine_Search_File
)
{
$relations
=
$this
->
buildRelation
();
}
$this
->
generateClass
(
$columns
,
$relations
);
$this
->
_options
[
'pluginTable'
]
=
$this
->
_options
[
'connection'
]
->
getTable
(
$this
->
_options
[
'className'
]);
return
true
;
$this
->
hasColumns
(
$columns
);
}
}
lib/Doctrine/Search/File.php
View file @
a5f755f4
...
...
@@ -51,7 +51,11 @@ class Doctrine_Search_File extends Doctrine_Search
$this
->
_options
[
'fields'
]
=
array
(
'url'
,
'content'
);
}
$this
->
buildPluginDefinition
(
$table
);
$this
->
initialize
(
$table
);
}
public
function
buildRelation
()
{
}
/**
* indexes given directory
...
...
lib/Doctrine/Template/I18n.php
View file @
a5f755f4
...
...
@@ -49,15 +49,7 @@ class Doctrine_Template_I18n extends Doctrine_Template
*/
public
function
setUp
()
{
$name
=
$this
->
_table
->
getComponentName
();
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$className
=
$this
->
_plugin
->
getOption
(
'className'
);
$id
=
$this
->
_table
->
getIdentifier
();
$this
->
hasMany
(
$className
.
' as Translation'
,
array
(
'local'
=>
$id
,
'foreign'
=>
$id
));
$this
->
_plugin
->
initialize
(
$this
->
_table
);
}
/**
...
...
lib/Doctrine/Template/Searchable.php
View file @
a5f755f4
...
...
@@ -37,18 +37,9 @@ class Doctrine_Template_Searchable extends Doctrine_Template
$this
->
_plugin
=
new
Doctrine_Search
(
$options
);
}
public
function
getPlugin
()
{
return
$this
->
_plugin
;
}
public
function
setUp
()
{
$id
=
$this
->
_table
->
getIdentifier
();
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$this
->
hasMany
(
$this
->
_plugin
->
getOption
(
'className'
),
array
(
'local'
=>
$id
,
'foreign'
=>
$id
));
$this
->
_plugin
->
initialize
(
$this
->
_table
);
$this
->
addListener
(
new
Doctrine_Search_Listener
(
$this
->
_plugin
));
}
...
...
lib/Doctrine/Template/Versionable.php
View file @
a5f755f4
...
...
@@ -38,7 +38,7 @@ class Doctrine_Template_Versionable extends Doctrine_Template
}
public
function
setUp
()
{
$this
->
_plugin
->
buildPluginDefinition
(
$this
->
_table
);
$this
->
_plugin
->
initialize
(
$this
->
_table
);
$this
->
hasColumn
(
'version'
,
'integer'
,
8
);
...
...
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