Skip to content
Snippets Groups Projects
Commit 87f2832c authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-98] Merging testing into staging (IMCE upgrade)

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@526 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 9e4383bb
No related branches found
No related tags found
No related merge requests found
; $Id: imce.info,v 1.7.2.1 2010/12/27 20:10:34 ufku Exp $ ; $Id: imce.info,v 1.7.2.2 2011/01/13 09:09:40 ufku Exp $
name = "IMCE" name = "IMCE"
description = "An image/file uploader and browser supporting personal directories and user quota." description = "An image/file uploader and browser supporting personal directories and user quota."
core = "7.x" core = "7.x"
package = "Media" package = "Media"
configure = "admin/config/media/imce"
; Information added by drupal.org packaging script on 2010-12-27 ; Information added by drupal.org packaging script on January 1, 1970 - 00:00
version = "7.x-1.1" version = "7.x-1.2"
core = "7.x" core = "7.x"
project = "imce" project = "imce"
datestamp = "1293481279" datestamp = "1296601518"
<?php <?php
// $Id: imce.install,v 1.8 2010/08/30 04:06:25 ufku Exp $ // $Id: imce.install,v 1.8.2.1 2011/01/18 08:56:19 ufku Exp $
/** /**
* @file * @file
...@@ -50,32 +50,48 @@ function imce_update_7000() { ...@@ -50,32 +50,48 @@ function imce_update_7000() {
if ($ids != '') { if ($ids != '') {
$ids = explode(',', $ids); $ids = explode(',', $ids);
foreach ($ids as &$id) { foreach ($ids as &$id) {
$id += '*'; $id .= '*';
} }
variable_set('imce_settings_textarea', implode(', ', $ids)); variable_set('imce_settings_textarea', implode(', ', $ids));
} }
} }
/** /**
* Migrates imce files from {files} to {file_managed}.
* Removes {imce_files} in favor of {file_usage}. * Removes {imce_files} in favor of {file_usage}.
*/ */
function imce_update_7001(&$sandbox) { function imce_update_7001(&$sandbox) {
if (!db_table_exists('imce_files')) { if (!db_table_exists('imce_files') || !db_table_exists('files')) {
return; return;
} }
// Initiate progress
if (!isset($sandbox['progress'])) { if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0; $sandbox['progress'] = 0;
$sandbox['last_fid_processed'] = -1; $sandbox['last_fid_processed'] = 0;
$sandbox['max'] = db_query("SELECT COUNT(*) FROM {imce_files}")->fetchField(); $sandbox['max'] = db_query("SELECT COUNT(*) FROM {imce_files} i INNER JOIN {files} f ON i.fid = f.fid")->fetchField();
} }
$limit = 500; // Prepare variables
$result = db_query_range('SELECT i.fid FROM {imce_files} i INNER JOIN {file_managed} f ON i.fid = f.fid WHERE i.fid > :fid ORDER BY i.fid', 0, $limit, array(':fid' => $sandbox['last_fid_processed']))->fetchAll(); $limit = 250;
$basedir = variable_get('file_directory_path', conf_path() . '/files') . '/';
$baselen = strlen($basedir);
$scheme = file_default_scheme() . '://';
$result = db_query_range('SELECT f.* FROM {imce_files} i INNER JOIN {files} f ON i.fid = f.fid WHERE i.fid > :fid ORDER BY i.fid', 0, $limit, array(':fid' => $sandbox['last_fid_processed']))->fetchAll();
// Migrate imce files from {files} to {file_managed}
foreach ($result as $file) { foreach ($result as $file) {
$relpath = substr($file->filepath, 0, $baselen) == $basedir ? substr($file->filepath, $baselen) : $file->filepath;
$file->uri = file_stream_wrapper_uri_normalize($scheme . $relpath);
unset($file->filepath);
if (!db_query("SELECT 1 FROM {file_managed} WHERE fid = :fid", array(':fid' => $file->fid))->fetchField()) {
drupal_write_record('file_managed', $file);
}
file_usage_add($file, 'imce', 'file', $file->fid); file_usage_add($file, 'imce', 'file', $file->fid);
$sandbox['progress']++; $sandbox['progress']++;
$sandbox['last_fid_processed'] = $file->fid; $sandbox['last_fid_processed'] = $file->fid;
} }
if ($sandbox['#finished'] = empty($sandbox['max']) || ($sandbox['progress'] / $sandbox['max'])) { // Drop {imce_files} if the progress is complete.
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
if ($sandbox['#finished'] >= 1) {
db_drop_table('imce_files'); db_drop_table('imce_files');
return t('Migrated IMCE files.');
} }
} }
\ No newline at end of file
<?php <?php
// $Id: imce.page.inc,v 1.10.2.3 2010/12/27 20:09:02 ufku Exp $ // $Id: imce.page.inc,v 1.10.2.4 2011/01/10 13:03:02 ufku Exp $
/** /**
* @file * @file
...@@ -279,7 +279,9 @@ function imce_fileop_form_validate($form, &$form_state) { ...@@ -279,7 +279,9 @@ function imce_fileop_form_validate($form, &$form_state) {
function imce_upload_submit($form, &$form_state) { function imce_upload_submit($form, &$form_state) {
$form_state['redirect'] = FALSE; $form_state['redirect'] = FALSE;
$imce =& $form_state['build_info']['args'][0]['imce']; $imce =& $form_state['build_info']['args'][0]['imce'];
$validators = array('imce_validate_all' => array(&$imce)); // Need to provide extension validatior, otherwise file_save_upload uses the default.
$validators['file_validate_extensions'] = array($imce['extensions'] === '*' ? NULL : $imce['extensions']);
$validators['imce_validate_all'] = array(&$imce);
$diruri = imce_dir_uri($imce); $diruri = imce_dir_uri($imce);
//save uploaded file. //save uploaded file.
...@@ -613,10 +615,6 @@ function imce_validate_all($file, $imce) { ...@@ -613,10 +615,6 @@ function imce_validate_all($file, $imce) {
if ($imce['quota']) { if ($imce['quota']) {
$errors = array_merge($errors, imce_validate_quota($file, $imce['quota'], $imce['dirsize'])); $errors = array_merge($errors, imce_validate_quota($file, $imce['quota'], $imce['dirsize']));
} }
//file extension validation
if ($imce['extensions'] != '*') {
$errors = array_merge($errors, file_validate_extensions($file, $imce['extensions']));
}
//user quota validation. check it if no errors were thrown. //user quota validation. check it if no errors were thrown.
if (empty($errors) && $imce['tuquota']) { if (empty($errors) && $imce['tuquota']) {
$errors = imce_validate_tuquota($file, $imce['tuquota'], file_space_used($imce['uid'])); $errors = imce_validate_tuquota($file, $imce['tuquota'], file_space_used($imce['uid']));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment