Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ctools
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
drupal.org
ctools
Commits
4078c7a5
Commit
4078c7a5
authored
16 years ago
by
Earl Miles
Browse files
Options
Downloads
Patches
Plain Diff
#367962: Remove incorrect "default" values from schema that prevents tables from being created.
parent
83b9366a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ctools.module
+96
-0
96 additions, 0 deletions
ctools.module
delegator/delegator.install
+0
-4
0 additions, 4 deletions
delegator/delegator.install
with
96 additions
and
4 deletions
ctools.module
+
96
−
0
View file @
4078c7a5
...
...
@@ -159,3 +159,99 @@ function ctools_cron() {
}
}
/**
* Initialize an object from schema.
*
* The schema for the table will be queried and flags on the fields will
* be used to initialize the data.
*
* - $schema['class'] will be used to determine the class of the new object.
* stdClass will be used if this is not set.
* - $schema['fields'][$field]['serialize'] will be queried to see if the
* data is serialized.
* - $schema['fields'][$field']'object default'] will be queried to see if
* the object gets a default that the database does not.
*
* @param $table
* The name of the table which must be available via drupal_get_schema().
*/
function
ctools_object_init
(
$table
)
{
$schema
=
drupal_get_schema
(
$table
);
if
(
!
$schema
)
{
return
;
}
$class
=
isset
(
$schema
[
'class'
])
&&
class_exists
(
$schema
[
'class'
])
?
$schema
[
'class'
]
:
'stdClass'
;
$object
=
new
$class
;
// Go through our schema and build correlations.
foreach
(
$schema
[
'fields'
]
as
$field
=>
$info
)
{
if
(
$info
[
'type'
]
==
'serial'
)
{
$object
->
$field
=
NULL
;
}
if
(
!
isset
(
$object
->
$field
))
{
if
(
!
empty
(
$info
[
'serialize'
])
&&
isset
(
$info
[
'serialized default'
]))
{
$object
->
$field
=
unserialize
(
$info
[
'serialized default'
]);
}
else
if
(
isset
(
$info
[
'default'
]))
{
$object
->
$field
=
$info
[
'default'
];
}
// Some database types do not support defaults but we want to
// provide one in code. This one will only be used on the in code
// object, never in the database.
else
if
(
isset
(
$info
[
'object default'
]))
{
$object
->
$field
=
$info
[
'object default'
];
}
else
{
$object
->
$field
=
''
;
}
}
}
return
$object
;
}
/**
* Load an object with data, presumably retrieved via db_fetch_object.
*
* @param &$object
* The object to load data onto. This will be modified in place.
* @param $table
* The name of the table, which will be loaded from schema.
* @param $data
* The data to load via db_fetch_object().
*/
function
ctools_object_load
(
&
$object
,
$table
,
$data
)
{
$schema
=
drupal_get_schema
(
$table
);
if
(
!
$schema
)
{
return
;
}
// Go through our schema and build correlations.
foreach
(
$schema
[
'fields'
]
as
$field
=>
$info
)
{
if
(
isset
(
$data
->
$field
)
{
$object
->
$field
=
empty
(
$info
[
'serialize'
])
?
$data
->
$field
:
unserialize
(
$data
->
$field
);
}
}
}
/**
* Create an object from data loaded from the database.
*
* @param $table
* The name of the table, which will be loaded from schema.
* @param $data
* The data to load via db_fetch_object().
*
* @return
* The initialized object.
*/
function
ctools_object_create
(
$table
,
$data
)
{
$object
=
ctools_object_init
(
$table
);
ctools_object_load
(
$object
,
$table
,
$data
);
return
$object
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
delegator/delegator.install
+
0
−
4
View file @
4078c7a5
...
...
@@ -60,7 +60,6 @@ function delegator_schema_1() {
'size'
=>
'big'
,
'description'
=>
t
(
'Serialized configuration of the handler, if needed.'
),
'not null'
=>
TRUE
,
'default'
=>
''
,
'serialize'
=>
TRUE
,
),
),
...
...
@@ -118,7 +117,6 @@ function delegator_schema_1() {
'size'
=>
'big'
,
'description'
=>
t
(
'Access configuration for this path.'
),
'not null'
=>
TRUE
,
'default'
=>
''
,
'serialize'
=>
TRUE
,
),
'multiple'
=>
array
(
...
...
@@ -132,7 +130,6 @@ function delegator_schema_1() {
'size'
=>
'big'
,
'description'
=>
t
(
'Serialized configuration of Drupal menu visibility settings for this item.'
),
'not null'
=>
TRUE
,
'default'
=>
''
,
'serialize'
=>
TRUE
,
),
'arguments'
=>
array
(
...
...
@@ -140,7 +137,6 @@ function delegator_schema_1() {
'size'
=>
'big'
,
'description'
=>
t
(
'Configuration of arguments for this menu item.'
),
'not null'
=>
TRUE
,
'default'
=>
''
,
'serialize'
=>
TRUE
,
),
),
...
...
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