Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL-CMS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric Rasmussen
UNL-CMS
Commits
85d760b7
Commit
85d760b7
authored
12 years ago
by
Eric Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
[gh-703] Add upload_replace patch and info to README
parent
1a9b4464
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
patches/upload_replace_error-1115484-13.patch
+109
-0
109 additions, 0 deletions
patches/upload_replace_error-1115484-13.patch
with
109 additions
and
0 deletions
patches/upload_replace_error-1115484-13.patch
0 → 100644
+
109
−
0
View file @
85d760b7
diff --git a/upload_replace.module b/upload_replace.module
index 0489f2d..7d1d644 100644
--- a/upload_replace.module
+++ b/upload_replace.module
@@ -15,60 +15,53 @@
/**
* Implementation of hook_file_update()
*/
-function upload_replace_file_update(&$new_file) {
+function upload_replace_file_update($new_file) {
if (!$new_file->fid) {
//Nothing to do if no fileid
return;
}
-
$desired_destination = preg_replace('/_[0-9]+\.(.*)$/', '.$1', $new_file->uri);
$db_path = db_select('file_managed', 'f')
- ->fields('f', array('uri', ))
+ ->fields('f', array('uri'))
->condition('fid', $new_file->fid)
->execute()
- ->fetchField();
- if ($db_path != $new_file->uri) {
+ ->fetchAssoc();
+ if ($db_path['uri'] != $new_file->uri) {
//this happens when a reversion is being reverted
- $next_good_filepath = file_destination($desired_destination, FILE_EXISTS_RENAME);
+ $next_good_uri = file_destination($desired_destination, FILE_EXISTS_RENAME);
db_update('file_managed')
- ->fields(array('uri' => $next_good_filepath))
+ ->fields(array('uri' => $next_good_uri))
->condition('fid', $new_file->fid)
->execute();
$new_file->uri = $desired_destination;
}
else {
//If the filename has be modified by adding a _0 value, or
- //on certain situations the filepath will not match the filepath in the db, such as
+ //on certain situations the uri will not match the uri in the db, such as
//when reverting a revision. When reverting a revision change the filename as well
- if (!strpos($new_file->uri, $new_file->uri)) {
- //the filename is not in the filepath, so drupal must have added a "_0" before the extension
+ if (!strpos($new_file->uri, $new_file->filename)) {
+ //the filename is not in the uri, so drupal must have added a "_0" before the extension
//find the file that is blocking this file from keeping the correct path
$result = db_select('file_managed', 'f')
->fields('f')
->condition('uri', $desired_destination)
->execute();
//@todo only one result is handled, should allow for multiple results
- $is_blocked = false;
-
foreach ($result as $file) {
$is_blocked = TRUE;
$blocking_file = $file;
- $tmp_destination = file_directory_temp() ."/$blocking_file->filename";
+ $tmp_destination = file_directory_temp()."/test_-".$blocking_file->fid."_-".$blocking_file->filename."";
}
- $old_destination = $db_path;
-
- if ($old_destination == $desired_destination){
- return;
- }
+ $old_destination = $db_path['uri'];
//Swap the files
if ($is_blocked) {
- //move the blocking file to a temporary location
+ //move the blocking file to a temparary location
if (!file_unmanaged_move($desired_destination, $tmp_destination)) {
drupal_set_message(t('The file %old could not be moved to %new', array('%old' => $desired_destination, '%new' => $tmp_destination)), 'error');
return;
}
- //DRUPAL 7 no longer changes the source filepath during move
+ //DRUPAL 7 no longer changes the source uri during move
//move blocking file was successful, update the DB
db_update('file_managed')
->fields(array('uri' => $tmp_destination))
@@ -107,10 +100,10 @@
function upload_replace_file_update(&$new_file) {
//Have to clear the cache because the revision data is cached somewhere
/*
* Find the nids where this file is used
- $query = "SELECT DISTINCT nid FROM {files} WHERE fid=%d";
+ $query = "SELECT DISTINCT id FROM {file_usage} WHERE fid=%d";
$result = db_query($query, $new_file->fid);
while($data = db_fetch_object($result)) {
- cache_clear_all("content:$data->nid");
+ cache_clear_all("node:$data->id");
}
*/
//This is inefficent, but how can we determine what nodes use this file?
@@ -118,11 +111,12 @@
function upload_replace_file_update(&$new_file) {
}
/**
- * HOOK_file_delete, update the filepath in the file object before deleting as we may have altered it above
+ * HOOK_file_delete, update the uri in the file object before deleting as we may have altered it above
* @param object $new_file
*/
/*
-function upload_replace_file_delete(&$file) {
- $file->filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $file->fid));
+function upload_replace_file_delete($file) {
+ $file->uri = db_result(db_query("SELECT uri FROM {file_managed} WHERE fid = %d", $file->fid));
}
-*/
\ No newline at end of file
+*/
+
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment