~ubuntu-branches/ubuntu/lucid/phpmyadmin/lucid

« back to all changes in this revision

Viewing changes to libraries/blobstreaming.lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-03-08 15:25:00 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100308152500-6e8hmuqc5co39de5
Tags: 4:3.3.0-1
* New upstream version.
* Rediff debian/patches.
* Fix permissions on mediawiki export extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
3
/**
4
 
 * @author          Raj Kissu Rajandran
5
 
 * @version     1.0
 
4
 * @author      Raj Kissu Rajandran and the team
6
5
 * @package     BLOBStreaming
7
6
 */
8
7
 
13
12
 * @uses    PMA_Config::get()
14
13
 * @uses    PMA_Config::settings()
15
14
 * @uses    PMA_Config::set()
16
 
 * @uses    PMA_PluginsExist()
17
15
 * @uses    PMA_BS_SetVariables()
18
16
 * @uses    PMA_BS_GetVariables()
19
17
 * @uses    PMA_BS_SetFieldReferences()
 
18
 * @uses    PMA_cacheSet()
 
19
 * @uses    PMA_cacheGet()
20
20
 * @return  boolean
21
21
*/
22
22
function checkBLOBStreamingPlugins()
25
25
    $PMA_Config = $_SESSION['PMA_Config'];
26
26
 
27
27
    // return if unable to load PMA configuration
28
 
    if (empty($PMA_Config))
 
28
    if (empty($PMA_Config)) {
29
29
        return FALSE;
30
 
 
31
 
    // retrieve current server configuration
32
 
    $serverCfg = $PMA_Config->get('Servers');
33
 
 
34
 
    if (isset($serverCfg[$GLOBALS['server']]))
35
 
        $serverCfg = $serverCfg[$GLOBALS['server']];
36
 
    else
37
 
        $serverCfg = null;
 
30
    }
 
31
 
 
32
    // At this point we might already know that plugins do not exist
 
33
    // because this was recorded in the session (cache).
 
34
    if (PMA_cacheGet('skip_blobstreaming', true)) {
 
35
        return false;
 
36
    }
 
37
 
 
38
    // If we don't know that we can skip blobstreaming, we continue
 
39
    // verifications; anyway, in case we won't skip blobstreaming,
 
40
    // we still need to set some variables in non-persistent settings,
 
41
    // which is done via $PMA_Config->set().
 
42
 
 
43
    /** Retrieve current server configuration;
 
44
     *  at this point, $PMA_Config->get('Servers') contains the server parameters
 
45
     *  as explicitely defined in config.inc.php, so it cannot be used; it's
 
46
     *  better to use $GLOBALS['cfg']['Server'] which contains the explicit
 
47
     *  parameters merged with the default ones
 
48
     *
 
49
     */
 
50
    $serverCfg = $GLOBALS['cfg']['Server'];
38
51
 
39
52
    // return if unable to retrieve current server configuration
40
 
    if (!isset($serverCfg))
 
53
    if (! $serverCfg) {
41
54
        return FALSE;
 
55
    }
42
56
 
43
57
    // if PHP extension in use is 'mysql', specify element 'PersistentConnections'
44
 
    if (isset($serverCfg['extension']) && "mysql" == $serverCfg['extension'])
 
58
    if ($serverCfg['extension'] == "mysql") {
45
59
        $serverCfg['PersistentConnections'] = $PMA_Config->settings['PersistentConnections'];
 
60
    }
46
61
 
47
62
    // if connection type is TCP, unload socket variable
48
 
    if (isset($serverCfg['connect_type']) && "tcp" == strtolower($serverCfg['connect_type']))
 
63
    if (strtolower($serverCfg['connect_type']) == "tcp") {
49
64
        $serverCfg['socket'] = "";
50
 
 
51
 
    // define BS Plugin variables
52
 
    $allPluginsExist = TRUE;
53
 
 
54
 
    $PMA_Config->set('PBXT_NAME', 'pbxt');
55
 
    $PMA_Config->set('PBMS_NAME', 'pbms');
56
 
 
57
 
    $plugins[$PMA_Config->get('PBXT_NAME')]['Library'] = 'libpbxt.so';
58
 
    $plugins[$PMA_Config->get('PBXT_NAME')]['Exists'] = FALSE;
59
 
 
60
 
    $plugins[$PMA_Config->get('PBMS_NAME')]['Library'] = 'libpbms.so';
61
 
    $plugins[$PMA_Config->get('PBMS_NAME')]['Exists'] = FALSE;
62
 
 
63
 
    // retrieve state of BS plugins
64
 
    PMA_PluginsExist($plugins);
65
 
 
66
 
    foreach ($plugins as $plugin_key=>$plugin)
67
 
        if (!$plugin['Exists'])
68
 
        {
69
 
            $allPluginsExist = FALSE;
70
 
            break;
71
 
        } // end if (!$plugin['Exists'])
72
 
 
73
 
    // set variable indicating BS plugin existance
 
65
    }
 
66
 
 
67
    $allPluginsExist = false;
 
68
    if (PMA_MYSQL_INT_VERSION >= 50109) {
 
69
        $PMA_Config->set('PBXT_NAME', 'pbxt');
 
70
        $PMA_Config->set('PBMS_NAME', 'pbms');
 
71
 
 
72
        $required_plugins[$PMA_Config->get('PBXT_NAME')]['Library'] = 'libpbxt.so';
 
73
        $required_plugins[$PMA_Config->get('PBMS_NAME')]['Library'] = 'libpbms.so';
 
74
        $number_of_required_plugins_found = 0;
 
75
 
 
76
        // Retrieve MySQL plugins
 
77
        $existing_plugins = PMA_DBI_fetch_result('SHOW PLUGINS');
 
78
 
 
79
        foreach ($existing_plugins as $one_existing_plugin)     {
 
80
            // check if required plugins exist
 
81
            foreach ($required_plugins as $one_required_plugin) {
 
82
                if ( strtolower($one_existing_plugin['Library']) == strtolower($one_required_plugin['Library'])
 
83
                        && $one_existing_plugin['Status'] == "ACTIVE") {
 
84
                    $number_of_required_plugins_found++;
 
85
                }
 
86
            }
 
87
            if (2 == $number_of_required_plugins_found) {
 
88
                $allPluginsExist = true;
 
89
                break;
 
90
            }
 
91
        }
 
92
       unset($required_plugins, $existing_plugins, $one_required_plugin, $one_existing_plugin, $number_of_required_plugins_found);
 
93
    }
 
94
    
 
95
    // set variable indicating BS plugin existence
74
96
    $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', $allPluginsExist);
75
97
 
76
 
    // do the plugins exist?
77
 
    if ($allPluginsExist)
78
 
    {
 
98
    if ($allPluginsExist) {
79
99
        // retrieve BS variables from PMA configuration
80
100
        $bs_set_variables = array();
81
101
 
90
110
        // retrieve updated BS variables (configurable and unconfigurable)
91
111
        $bs_variables = PMA_BS_GetVariables();
92
112
 
93
 
        // if no BS variables exist, set plugin existance to false and return
94
 
        if (count($bs_variables) <= 0)
95
 
        {
 
113
        // if no BS variables exist, set plugin existence to false and return
 
114
        if (count($bs_variables) <= 0) {
96
115
            $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
 
116
            PMA_cacheSet('skip_blobstreaming', true, true);
97
117
            return FALSE;
98
118
        } // end if (count($bs_variables) <= 0)
99
119
 
100
120
        // switch on BS field references
101
 
        if (strtolower($bs_variables[$PMA_Config->get('PBMS_NAME') . '_field_references']) == "off")
102
 
            if(!PMA_BS_SetFieldReferences('ON'))
103
 
                    return FALSE;
 
121
        if (strtolower($bs_variables[$PMA_Config->get('PBMS_NAME') . '_field_references']) == "off") {
 
122
            if (! PMA_BS_SetFieldReferences('ON')) {
 
123
                PMA_cacheSet('skip_blobstreaming', true, true);
 
124
                return FALSE;
 
125
            }
 
126
        }
104
127
 
105
128
        // get BS server port
106
129
        $BS_PORT = $bs_variables[$PMA_Config->get('PBMS_NAME') . '_port'];
107
130
 
108
131
        // if no BS server port exists, set plugin existance to false and return
109
 
        if (!$BS_PORT)
110
 
        {
 
132
        if (! $BS_PORT) {
111
133
            $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
 
134
            PMA_cacheSet('skip_blobstreaming', true, true);
112
135
            return FALSE;
113
136
        } // end if (!$BS_PORT)
114
137
 
120
143
        $PMA_Config->set('FILEINFO_EXISTS', FALSE);
121
144
 
122
145
        // check if CURL exists
123
 
        if (function_exists("curl_init"))
124
 
        {
 
146
        if (function_exists("curl_init")) {
125
147
            // initialize curl handler
126
148
            $curlHnd = curl_init();
127
149
 
128
150
            // CURL exists, set necessary variable and close resource
129
 
            if (!empty($curlHnd))
130
 
            {
 
151
            if (! empty($curlHnd)) {
131
152
                $PMA_Config->set('CURL_EXISTS', TRUE);
132
153
                curl_close($curlHnd);                
133
154
            } // end if (!empty($curlHnd))
136
157
        // check if PECL's fileinfo library exist
137
158
        $finfo = NULL;
138
159
 
139
 
        if (function_exists("finfo_open"))
 
160
        if (function_exists("finfo_open")) {
140
161
            $finfo = finfo_open(FILEINFO_MIME);
 
162
        }
141
163
 
142
164
        // fileinfo library exists, set necessary variable and close resource
143
 
        if (!empty($finfo))
144
 
        {
 
165
        if (! empty($finfo)) {
145
166
            $PMA_Config->set('FILEINFO_EXISTS', TRUE);
146
167
            finfo_close($finfo);
147
168
        } // end if (!empty($finfo))
 
169
    } else {
 
170
        PMA_cacheSet('skip_blobstreaming', true, true);
 
171
        return FALSE;
148
172
    } // end if ($allPluginsExist)
149
 
    else
150
 
        return FALSE;
151
173
 
152
174
    $bs_tables = array();
153
175
 
220
242
    // load PMA configuration
221
243
    $PMA_Config = $_SESSION['PMA_Config'];
222
244
 
223
 
    // return if unable to load PMA configuration
224
 
    if (empty($PMA_Config))
225
 
        return;
 
245
    $serverCfg = $GLOBALS['cfg']['Server'];
226
246
 
227
247
    // retrieve BS tables from PMA configuration
228
248
    $session_bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES');
255
275
    $PMA_Config->set('BLOBSTREAMABLE_DATABASES', $bs_databases);
256
276
}
257
277
 
258
 
/**
259
 
 * checks whether a set of plugins exist
260
 
 *
261
 
 * @access  public
262
 
 * @param   array - a list of plugin names and accompanying library filenames to check for
263
 
 * @uses    PMA_DBI_query()
264
 
 * @uses    PMA_DBI_fetch_assoc()
265
 
*/
266
 
function PMA_PluginsExist(&$plugins)
267
 
{   
268
 
    if (PMA_MYSQL_INT_VERSION < 50109) {
269
 
        return;
270
 
    }
271
 
    // run query to retrieve MySQL plugins
272
 
    $query = "SHOW PLUGINS";
273
 
    $result = PMA_DBI_query($query);
274
 
 
275
 
    // while there are records to parse
276
 
        while ($data = @PMA_DBI_fetch_assoc($result))
277
 
        {
278
 
        // reset plugin state
279
 
        $state = TRUE;
280
 
 
281
 
        // check if required plugins exist
282
 
                foreach ($plugins as $plugin_key=>$plugin)
283
 
                        if (!$plugin['Exists'])
284
 
                                if (
285
 
                                        strtolower($data['Library']) == strtolower($plugin['Library']) &&
286
 
                                        $data['Status'] == "ACTIVE"
287
 
                                   )
288
 
                                        $plugins[$plugin_key]['Exists'] = TRUE;
289
 
                else
290
 
                    if ($state)
291
 
                        $state = FALSE;
292
 
 
293
 
        // break if all necessary plugins are found before all records are parsed
294
 
        if ($state)
295
 
            break;
296
 
    } // end while ($data = @PMA_DBI_fetch_assoc($result))
297
 
}
 
278
 
298
279
 
299
280
/**
300
281
 * checks whether a given set of tables exist in a given database