-
Notifications
You must be signed in to change notification settings - Fork 188
[document_repository] Solves special characters issue #7383
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 5 commits into
aces:23.0-release
from
pierre-p-s:2021_03_10_Doc_Repo_Special_Chars
Apr 15, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
55 changes: 55 additions & 0 deletions
55
tools/single_use/Cleanup_Special_Chars_Document_Repository.php
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,55 @@ | ||
| <?php | ||
| /** | ||
| * This script is written to clean up the files with special characters from the document repository 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_Document_Repository.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(); | ||
|
|
||
| $document_repository_path = $config->getSetting('documentRepositoryPath'); | ||
|
|
||
| $data = $DB->pselect( | ||
| "SELECT record_id, File_name, uploaded_by | ||
| FROM document_repository", | ||
| [] | ||
| ); | ||
|
|
||
| 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( | ||
| "document_repository", | ||
| [ | ||
| "file_name" => $fileName, | ||
| "Data_dir" => $fileName | ||
| ], | ||
| [ | ||
| "record_id" => $file['record_id'] | ||
| ] | ||
| ); | ||
|
|
||
| // update name in file system | ||
| shell_exec("mv " . escapeshellarg($document_repository_path . $file['uploaded_by'] . "/" . $fileNameURLencoded) . " " . escapeshellarg($document_repository_path . $file['uploaded_by'] . "/" . $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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before SQL