Module Loader - file_get_contents restriction

Hello,
as per official guide teh file_get_contents() function is disabled by default.

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_8.0/Architecture/Module_Loader/Module_Loader_Restriction_Alternatives/#file_get_contents

Of course you could override this behaviour but i would use alternative method provided by Suite.

I’ve cerated a zip package that execute a post install script which should retrieve a file content.

the alternative method looks like:

require_once('include/upload_file.php');

$uploadFile = new UploadFile();

//get the file location
$uploadFile->temp_file_location = UploadFile::get_upload_path($file_id);
$file_contents = $uploadFile->get_file_contents();

But how retrieve a specific file content inside a specific folder(ex: subdirectory inside my scripts folder in the zip package) if i don’t know the $file_id?

How to passing the right file_id?

Thank you for any hint.

Regards

Whose “official documentation” is that? And where does it say " file_get_contents() function is disabled by default"? I don’t find that there… :huh:

It seems the UploadFile class is for files you upload into SuiteCRM as Docuements/Attachements/etc. I wouldn’t use it unless that is really the sort of object you want to handle.

I’m not sure exactly what your requirements are, but i would say If you’re just doing your own processing, stick to the regular PHP functions. You will surely find many examples of handling stuff inside zips. Then when you have your data sorted out you can put into SuiteCRM objects.

Not sure this helps, but it’s the best advice I can give with what I know…

Hello,
thank for your quick reply.

Regarding file_get_content() i’ve tried by myself…so after adding a specific override in config this traditional php function had worked:

 $sugar_config['disable_persistent_connections'] = false;
$sugar_config['moduleInstaller']['blackListExempt'] = array(
            'file_get_contents'
        );

My needs is to distribute inside a zip package a .sql files in order to make an initial sql query to insert some defaults records(ex: acl roles).

So what i’ve done so far is:

  1. set config_override
  2. upload package
  3. distribute files with manifest
  4. launch post_install script which get sql file contents and execute insert query.

What i would do is to avoid to insert the config_override and use safer methods.

Regards

I’m sorry, I never used that UploadFile class and I don’t know exactly how it is meant to be used…

From a brief view, it looks like it’s meant for files uploaded into SuiteCRM (through notes and attachments) so probably you can get the file_id if you are able to upload it along with one of those beans. But I might be completely lost on this.

This might (just maybe!) help: https://pgorod.github.io/How-Attachments-Stored/

I would also try a crazy test: put the file in the “upload” folder with a name like the typical SuiteCRM ids:

253f7828-e4f5-4d81-e1f3-5ae08add8c3a

Then use that as file_id to see if it fetches the file…

Or even simpler, given the way this is written:

https://github.com/salesagility/SuiteCRM/blob/master/include/UploadFile.php#L391

Just give it a path directly and it should load the contents:

$uploadFile->temp_file_location = 'upload/YourFile.sql';
$file_contents = $uploadFile->get_file_contents();