Fixing document location

jexmex wrote on Wednesday, August 24, 2016:

We just moved the OpenEMR system to a new host. The documents table has the urls hardcoded to the full path from the old host. Is there a built-in method to fix this? I know I can construct a SQL, but was hoping for something a bit more builtin to fix it.

bradymiller wrote on Wednesday, August 24, 2016:

Hi Craig,

You shouldn’t need to do this since OpenEMR doesn’t use the full path in the documents module. If it isn’t working, then would consider it a bug that should be fixed in the codebase.

-brady
OpenEMR

jexmex wrote on Wednesday, August 24, 2016:

In the database for the url column all files are either file://path/to/old/location/file.pdf or /path/to/old/location. I had to hardcode the path in globals.php, which seemed to fix some of the documents, but others still try to load from the old location.

bradymiller wrote on Wednesday, August 24, 2016:

Hi Craig,

Note the documents algorithm just pops items off the end of the path:

If this is breaking for you, then would be curious to know your OpenEMR version, where it is breaking, and also what you had to set in the global.php? (I am assuming both are in sites//documents; lt me know if that is an incorrect assumption).

-brady
OpenEMR

jexmex wrote on Wednesday, August 24, 2016:

Going to in to view the documents it will say that it does not exist or permissions are not correct for /the/old/path/to/file/file.pdf. The structure is the same (sites/default/documents) for both, It is just the absolute path that is wrong. I believe we are behind one patch or so right now.(v4.2.1)

bradymiller wrote on Wednesday, August 24, 2016:

Hi,
If you fix the path in 1 of them manually, does it then work?
-brady

mdsupport wrote on Wednesday, August 24, 2016:

It is a bug / feature depending on how it is used …

Upload Report
ID: 2
Patient: 1
URL: file:///var/www/openemr/sites/default/documents/1/Path_Test.pdf
Size: 579867
Date: 2016-08-24 10:22:44
Hash: 8e14de300d6819152b202700225b46442a6fa976
MimeType: application/pdf
Revision: 2016-08-24 10:22:44

Could not verify url in database but here is fragment of how files are moved…

		  	//now move the file
		  	if (rename($d->get_url_filepath(),$new_path.$fname)) {
		  		$d->url = "file://" .$new_path.$fname;

mdsupport wrote on Wednesday, August 24, 2016:

Short answer is no. Of course you could create a link since the hardcoded url does not include host but one of these days you will want to run a global replace. Also look around - some scripts are storing with prefix “file://” while some do not.

jexmex wrote on Wednesday, August 24, 2016:

I will try this evening. It is almost like the location is cached and used somewhere.