-
Notifications
You must be signed in to change notification settings - Fork 188
[media] Special characters issue #7386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
driusan
merged 11 commits into
aces:23.0-release
from
pierre-p-s:2021_03_11_Media_Special_Chars
Apr 20, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e116277
[media] Special characters issue
14b7a8d
Addressing Rida's comments
f2277e6
Addressing Rida's comment
e3dd1e9
First pass a script
f307fe6
Script working
53fbc4a
Update modules/media/ajax/FileUpload.php
pierre-p-s 0d80019
Trying to fix test suite
f94e4df
Fixed test suite
aa2ecd3
Addressing Jessica's comments
e372f74
Addressing Dave's comment
1ada058
Solves escape issue
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before SQL |
||
| /** | ||
| * This script is written to clean up the files with special characters from the media data table as well as clean up the | ||
| * quotes appearing as %22 in the file names in the file system | ||
| * | ||
| * To use the script: php Cleanup_Special_Chars_Media.php | ||
| * | ||
| * | ||
| * PHP Version 7 | ||
| * | ||
| * @category Main | ||
| * @package Loris | ||
| * @author Pierre PAC SOO <pierre.pacsoo@mcin.ca> | ||
| * @license Loris license | ||
| * @link https://www.github.com/aces/Loris-Trunk/ | ||
| */ | ||
|
|
||
| require_once __DIR__."/../generic_includes.php"; | ||
| $config = NDB_Config::singleton(); | ||
|
|
||
| $media_path = $config->getSetting('mediaPath'); | ||
|
|
||
| $data = $DB->pselect( | ||
| "SELECT id, file_name | ||
| FROM media", | ||
| [] | ||
| ); | ||
|
|
||
| foreach($data as $key => $file) { | ||
|
|
||
| // fileNameURLencoded is needed for the step line 48 as the file name got rid of '"' and replaced it with %22 | ||
| // urldecode will get rid of %22 and replace it correctly for it to be inserted into the table | ||
| $fileNameURLencoded = htmlspecialchars_decode($file['file_name']); | ||
| $fileName = urldecode($fileNameURLencoded); | ||
|
|
||
| // update only if file name has been updated | ||
| if($fileName !== $file['file_name']) { | ||
|
|
||
| // change name in sql table media | ||
| $DB->unsafeupdate( | ||
| "media", | ||
| [ | ||
| "file_name" => $fileName | ||
| ], | ||
| [ | ||
| "id" => $file['id'] | ||
| ] | ||
| ); | ||
|
|
||
| // update name in file system | ||
| rename($media_path.$fileNameURLencoded, $media_path.$fileName); | ||
| print("Old file name: " . $file['file_name'] . ". New file name: " . $fileName . "\n\n"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.