function migrate_example_oracle_requirements in Migrate 7.2
Same name and namespace in other branches
- 6.2 migrate_example/migrate_example_oracle/migrate_example_oracle.install \migrate_example_oracle_requirements()
Implements hook_requirements().
File
- migrate_example/
migrate_example_oracle/ migrate_example_oracle.install, line 110 - Set up the Oracle migration example module.
Code
function migrate_example_oracle_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'install':
// Check that the OCI8 extension is loaded
$requirements['oci8'] = array(
'title' => $t('Oracle extension'),
);
if (!extension_loaded('oci8')) {
$requirements['oci8']['description'] = $t('Migrating from an Oracle
database requires that you have the !link extension loaded in PHP.', array(
'!link' => l('oci8', 'http://us.php.net/manual/en/book.oci8.php'),
));
$requirements['oci8']['severity'] = REQUIREMENT_ERROR;
break;
}
$sample_setting = '<pre>
$conf[\'oracle_db\'] = array(
\'username\' => \'Oracle_username\',
\'password\' => \'Oracle_password\',
\'connection_string\' => \'//Oracle_host/SID\',
);
</pre>';
// Check that there is an Oracle database configured for use
$requirements['oracle_db'] = array(
'title' => $t('Oracle configuration'),
);
global $conf;
if (empty($conf['oracle_db']) || empty($conf['oracle_db']['username']) || empty($conf['oracle_db']['password']) || empty($conf['oracle_db']['connection_string'])) {
$requirements['oracle_db']['description'] = $t('You must define $conf[\'oracle_db\']
(in your site\'s settings.php file) to point to the Oracle database where
you want test data to be stored: ' . $sample_setting);
$requirements['oracle_db']['severity'] = REQUIREMENT_ERROR;
break;
}
// Check that we can connect to the Oracle db.
$requirements['oracle_connect'] = array(
'title' => $t('Oracle connection available'),
);
$connection = oci_connect($conf['oracle_db']['username'], $conf['oracle_db']['password'], $conf['oracle_db']['connection_string'], 'UTF8');
if (!$connection) {
$e = oci_error();
$requirements['oracle_connect']['description'] = $t('Could not connect to configured
Oracle database at !conn_string. Oracle error message: !message', array(
'!conn_string' => $conf['oracle_db']['connection_string'],
'!message' => $e['message'],
));
$requirements['oracle_connect']['severity'] = REQUIREMENT_ERROR;
break;
}
// Check for necessary privileges
$requirements['oracle_privs'] = array(
'title' => $t('Necessary Oracle privileges are assigned'),
);
$statement = oci_parse($connection, 'SELECT * FROM SESSION_PRIVS');
if (!$statement) {
$e = oci_error($connection);
$requirements['oracle_connect']['description'] = $e['message'];
$requirements['oracle_connect']['severity'] = REQUIREMENT_ERROR;
break;
}
$result = oci_execute($statement);
if (!$result) {
$e = oci_error($statement);
$requirements['oracle_connect']['description'] = $e['message'];
$requirements['oracle_connect']['severity'] = REQUIREMENT_ERROR;
break;
}
$ok = FALSE;
while ($row = oci_fetch_object($statement)) {
if ($row->PRIVILEGE == 'CREATE TABLE') {
$ok = TRUE;
break;
}
}
if (!$ok) {
$requirements['oracle_privs']['description'] = $t('The specified
username !username does not have the CREATE TABLE privilege. This privilege
is necessary to create test tables in the Oracle database.', array(
'!username' => $conf['oracle_db']['username'],
));
$requirements['oracle_privs']['severity'] = REQUIREMENT_ERROR;
break;
}
break;
case 'update':
break;
case 'runtime':
break;
}
return $requirements;
}