View source
<?php
require_once dirname(__FILE__) . '/field_file.inc';
function filefield_install() {
drupal_load('module', 'content');
content_notify('install', 'filefield');
}
function filefield_uninstall() {
drupal_load('module', 'content');
content_notify('uninstall', 'filefield');
}
function filefield_enable() {
drupal_load('module', 'content');
content_notify('enable', 'filefield');
}
function filefield_disable() {
drupal_load('module', 'content');
content_notify('disable', 'filefield');
}
function filefield_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
drupal_load('module', 'filefield');
$implementation = filefield_progress_implementation();
$apache = strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== FALSE;
$fastcgi = strpos($_SERVER['SERVER_SOFTWARE'], 'mod_fastcgi') !== FALSE || strpos($_SERVER["SERVER_SOFTWARE"], 'mod_fcgi') !== FALSE;
$php_52 = version_compare(phpversion(), '5.2.0', '>');
$description = NULL;
if (!$apache || !$php_52) {
$value = $t('Not enabled');
$description = $t('Your server is not capable of displaying file upload progress. File upload progress requires PHP 5.2 and an Apache server.');
$severity = REQUIREMENT_INFO;
}
elseif ($fastcgi) {
$value = $t('Not enabled');
$description = $t('Your server is not capable of displaying file upload progress. File upload progress requires PHP be run with mod_php and not as FastCGI.');
$severity = REQUIREMENT_INFO;
}
elseif (!$implementation && extension_loaded('apc')) {
$value = $t('Not enabled');
$description = $t('Your server is capable of displaying file upload progress through APC, but it is not enabled. Add <code>apc.rfc1867 = 1</code> to your php.ini configuration. Alternatively, it is recommended to use <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>, which supports more than one simultaneous upload.');
$severity = REQUIREMENT_INFO;
}
elseif (!$implementation) {
$value = $t('Not enabled');
$description = t('Your server is capable of displaying file upload progress, but does not have the required libraries. It is recommended to install the <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a> (preferred) or to install <a href="http://us2.php.net/apc">APC</a>.');
$severity = REQUIREMENT_INFO;
}
elseif ($implementation == 'apc') {
$value = $t('Enabled (<a href="http://php.net/manual/en/apc.configuration.php#ini.apc.rfc1867">APC RFC1867</a>)');
$description = t('Your server is capable of displaying file upload progress using APC RFC1867. Note that only one upload at a time is supported. It is recommended to use the <a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress library</a> if possible.');
$severity = REQUIREMENT_OK;
}
elseif ($implementation == 'uploadprogress') {
$value = $t('Enabled (<a href="http://pecl.php.net/package/uploadprogress">PECL uploadprogress</a>)');
$severity = REQUIREMENT_OK;
}
$requirements['filefield_progress'] = array(
'title' => $t('Upload progress'),
'value' => $value,
'severity' => $severity,
'description' => $description,
);
}
return $requirements;
}
function filefield_update_last_removed() {
return 3;
}
function filefield_update_6001() {
if ($abort = content_check_update('filefield')) {
return $abort;
}
$ret = array();
module_load_include('inc', 'content', 'includes/content.admin');
$ret[] = update_sql("UPDATE {content_node_field} SET type = 'filefield', module = 'filefield', active = 1 WHERE type = 'file'");
$ret[] = update_sql("UPDATE {content_node_field_instance} SET widget_type = 'filefield_widget', widget_module = 'filefield', widget_active = 1 WHERE widget_type = 'file'");
$result = db_query("SELECT * FROM {content_node_field} WHERE type = 'filefield'");
while ($field = db_fetch_object($result)) {
$updated = FALSE;
$field_settings = unserialize($field->global_settings);
if (!isset($field_settings['list_default']) || !is_numeric($field_settings['list_default'])) {
$field_settings['list_default'] = 1;
$updated = TRUE;
}
if (!empty($field_settings['force_list'])) {
$field_settings['list_default'] = 1;
$field_settings['force_list_default'] = 1;
$updated = TRUE;
}
if ($updated) {
db_query("UPDATE {content_node_field} SET global_settings = '%s' WHERE field_name = '%s'", serialize($field_settings), $field->field_name);
}
}
content_associate_fields('filefield');
$fields = array();
foreach (content_types_install() as $type_name => $type_fields) {
foreach ($type_fields as $field) {
if ($field['type'] == 'filefield') {
$fields[$field['field_name']] = $field;
}
}
}
foreach ($fields as $field) {
$new_field = $field;
$field['columns']['description'] = array(
'type' => 'varchar',
);
$field['columns']['fid']['not null'] = TRUE;
$field['columns']['list']['not null'] = TRUE;
unset($field['columns']['data']);
$new_field['columns']['data'] = array(
'type' => 'text',
'serialize' => TRUE,
);
$new_field['columns']['fid']['not null'] = FALSE;
$new_field['columns']['list']['size'] = 'tiny';
$new_field['columns']['list']['not null'] = FALSE;
unset($new_field['columns']['description']);
content_alter_db($field, $new_field);
}
$batch = array(
'title' => t('Migrating filefield values'),
'operations' => array(),
'file' => drupal_get_path('module', 'filefield') . '/filefield.install',
);
foreach ($fields as $field_name => $field) {
if ($field['type'] == 'filefield') {
$batch['operations'][] = array(
'_filefield_update_6001_move_operation',
array(
$field,
),
);
$batch['operations'][] = array(
'_filefield_update_6001_drop_operation',
array(
$field,
),
);
}
}
batch_set($batch);
cache_clear_all('*', content_cache_tablename(), TRUE);
cache_clear_all('*', 'cache', TRUE);
return $ret;
}
function filefield_update_6100() {
$ret = array();
module_load_include('inc', 'content', 'includes/content.crud');
$fields = content_fields();
foreach ($fields as $field) {
if ($field['type'] == 'filefield') {
if (isset($field['force_list_default'])) {
$field['list_field'] = !$field['force_list_default'];
}
if (isset($field['show_description'])) {
$field['description_field'] = $field['show_description'];
}
_content_field_write($field);
$ret[] = array(
'success' => TRUE,
'query' => t('The file field %field has been updated with new settings.', array(
'%field' => $field['field_name'],
)),
);
}
}
cache_clear_all('*', content_cache_tablename(), TRUE);
cache_clear_all('*', 'cache', TRUE);
return $ret;
}
function filefield_update_6101() {
$ret = array();
module_load_include('inc', 'content', 'includes/content.crud');
$fields = content_fields();
foreach ($fields as $field) {
if ($field['type'] == 'filefield') {
$db_info = content_database_info($field);
if (isset($db_info['columns']['fid'])) {
$table = $db_info['table'];
$fid_column = $db_info['columns']['fid']['column'];
$list_column = $db_info['columns']['list']['column'];
$ret[] = update_sql("UPDATE {" . $table . "} SET {$fid_column} = NULL, {$list_column} = NULL WHERE {$fid_column} NOT IN (SELECT fid FROM {files})");
}
}
}
return $ret;
}
function filefield_update_6102(&$sandbox) {
return array();
}
function filefield_update_6103() {
$ret = array();
$ret[] = update_sql("UPDATE {" . content_instance_tablename() . "} SET widget_type = 'filefield_widget' WHERE widget_type = 'filefield_combo'");
cache_clear_all('*', content_cache_tablename(), TRUE);
cache_clear_all('*', 'cache', TRUE);
return $ret;
}
function filefield_update_6104() {
$ret = array();
$ret[] = update_sql("DELETE FROM {system} WHERE type = 'module' AND name = 'filefield_token'");
return $ret;
}
function _filefield_update_6001_move_operation($field, &$context) {
if (!isset($context['sandbox']['processed_files'])) {
$db_info = content_database_info($field);
$context['sandbox']['db_info'] = $db_info;
$context['sandbox']['table'] = $db_info['table'];
$context['sandbox']['col_data'] = $db_info['columns']['data']['column'];
$context['sandbox']['col_desc'] = $db_info['columns']['description']['column'];
$context['sandbox']['max'] = db_result(db_query("SELECT COUNT(*) FROM {" . $db_info['table'] . "}"));
$context['sandbox']['current_node'] = 0;
$context['sandbox']['current_delta'] = 0;
$context['sandbox']['processed_files'] = array();
}
$limit = 50;
$result = NULL;
if ($field['multiple']) {
$result = db_query_range("SELECT * FROM {{$context['sandbox']['table']}} WHERE (vid = %d AND delta > %d) OR vid > %d ORDER BY vid ASC, delta ASC", $context['sandbox']['current_node'], $context['sandbox']['current_delta'], $context['sandbox']['current_node'], 0, $limit);
}
else {
$result = db_query_range("SELECT * FROM {{$context['sandbox']['table']}} WHERE vid >= %d ORDER BY vid ASC", $context['sandbox']['current_node'], 0, $limit);
}
while ($row = db_fetch_array($result)) {
$delta = isset($row['delta']) ? $row['delta'] : 0;
if (isset($context['sandbox']['processed_files'][$row['vid'] . '_' . $delta])) {
continue;
}
if (!empty($row[$context['sandbox']['col_data']])) {
$data = unserialize($row[$context['sandbox']['col_data']]);
}
if (empty($data)) {
$data = array();
}
$data['description'] = $row[$context['sandbox']['col_desc']];
db_query("UPDATE {{$context['sandbox']['table']}} SET {$context['sandbox']['col_data']} = '%s' WHERE vid = %d", serialize($data), $row['vid']);
$context['sandbox']['processed_files'][$row['vid'] . '_' . $delta] = TRUE;
$context['sandbox']['current_node'] = $row['vid'];
$context['sandbox']['current_delta'] = $delta;
}
$processed_count = count($context['sandbox']['processed_files']);
if ($processed_count != $context['sandbox']['max']) {
$context['finished'] = $processed_count / $context['sandbox']['max'];
}
}
function _filefield_update_6001_drop_operation($field, &$context) {
$ret = array();
$db_info = content_database_info($field);
db_drop_field($ret, $db_info['table'], $db_info['columns']['description']['column']);
$context['finished'] = 1;
}