/[drupal]/contributions/modules/replication/bootstrap.inc.patch
ViewVC logotype

Contents of /contributions/modules/replication/bootstrap.inc.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Nov 5 15:02:55 2007 UTC (2 years ago) by rooey
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-patch
by Rooey. Initial replication module checkin
1 --- ../../includes/bootstrap.inc 2007-11-05 17:03:51.479185501 +0100
2 +++ bootstrap.inc 2007-11-05 17:14:24.410741249 +0100
3 @@ -828,6 +828,7 @@ function drupal_bootstrap($phase) {
4
5 function _drupal_bootstrap($phase) {
6 global $conf;
7 + global $local_conf;
8
9 switch ($phase) {
10
11 @@ -865,6 +866,7 @@ function _drupal_bootstrap($phase) {
12 case DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE:
13 // Initialize configuration variables, using values from settings.php if available.
14 $conf = variable_init(isset($conf) ? $conf : array());
15 + $local_conf = local_variable_init(isset($local_conf) ? $local_conf : array());
16
17 _drupal_cache_init($phase);
18
19 @@ -948,3 +950,131 @@ function get_t() {
20 }
21 return $t;
22 }
23 +/**
24 + * Load the persistent variable table.
25 + *
26 + * The local_variable table is composed of values that have been saved in the table
27 + * with local_variable_set() as well as those explicitly specified in the configuration
28 + * file.
29 + */
30 +
31 +function local_variable_init($local_conf = array()) {
32 + // NOTE: caching the variables improves performance by 20% when serving cached pages.
33 + if ($cached = cache_get('local_variables', 'cache')) {
34 + $local_variables = unserialize($cached->data);
35 + }
36 + else {
37 + $result = db_query('SELECT * FROM {local_variable}');
38 + while ($local_variable = db_fetch_object($result)) {
39 + $local_variables[$local_variable->name] = unserialize($local_variable->value);
40 + }
41 + cache_set('local_variables', 'cache', serialize($local_variables));
42 + }
43 +
44 + foreach ($local_conf as $name => $value) {
45 + $local_variables[$name] = $value;
46 + }
47 +
48 + return $local_variables;
49 +}
50 +
51 +/**
52 + * Return a persistent variable.
53 + *
54 + * @param $name
55 + * The name of the variable to return.
56 + * @param $default
57 + * The default value to use if this variable has never been set.
58 + * @return
59 + * The value of the variable.
60 + */
61 +function local_variable_get($name, $default) {
62 + global $local_conf;
63 +
64 + return isset($local_conf[$name]) ? $local_conf[$name] : $default;
65 +}
66 +
67 +/**
68 + * Set a persistent variable.
69 + *
70 + * @param $name
71 + * The name of the variable to set.
72 + * @param $value
73 + * The value to set. This can be any PHP data type; these functions take care
74 + * of serialization as necessary.
75 + */
76 +function local_variable_set($name, $value) {
77 + global $local_conf;
78 +
79 + db_lock_table('local_variable');
80 + db_query("DELETE FROM {local_variable} WHERE name = '%s'", $name);
81 + db_query("INSERT INTO {local_variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
82 + db_unlock_tables();
83 +
84 + cache_clear_all('local_variables', 'cache');
85 +
86 + $local_conf[$name] = $value;
87 +}
88 +
89 +/**
90 + * Unset a persistent variable.
91 + *
92 + * @param $name
93 + * The name of the variable to undefine.
94 + */
95 +function local_variable_del($name) {
96 + global $local_conf;
97 +
98 + db_query("DELETE FROM {local_variable} WHERE name = '%s'", $name);
99 + cache_clear_all('local_variables', 'cache');
100 +
101 + unset($local_conf[$name]);
102 +}
103 +
104 +/**
105 + * Execute the system_settings_form.
106 + *
107 + * If you want node type configure style handling of your checkboxes,
108 + * add an array_filter value to your form.
109 + *
110 + */
111 +function local_system_settings_form_submit($form_id, $form_values) {
112 + $op = isset($form_values['op']) ? $form_values['op'] : '';
113 +
114 + // Exclude unnecessary elements.
115 + unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
116 +
117 + foreach ($form_values as $key => $value) {
118 + if ($op == t('Reset to defaults')) {
119 + local_variable_del($key);
120 + }
121 + else {
122 + if (is_array($value) && isset($form_values['array_filter'])) {
123 + $value = array_keys(array_filter($value));
124 + }
125 + local_variable_set($key, $value);
126 + }
127 + }
128 + if ($op == t('Reset to defaults')) {
129 + drupal_set_message(t('The local configuration options have been reset to their default values.'));
130 + }
131 + else {
132 + drupal_set_message(t('The local configuration options have been saved.'));
133 + }
134 +
135 + menu_rebuild();
136 +}
137 +
138 +/**
139 + * Add default buttons to a form and set its prefix
140 + */
141 +function local_system_settings_form($form) {
142 + $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
143 + $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
144 +
145 + if (!empty($_POST) && form_get_errors()) {
146 + drupal_set_message(t('The local settings have not been saved because of the errors.'), 'error');
147 + }
148 + $form['#base'] = 'local_system_settings_form';
149 + return $form;
150 +}

  ViewVC Help
Powered by ViewVC 1.1.2