Commit f8110268 authored by jaapjansma's avatar jaapjansma

refactored createPDF action

parent ee586ecd
......@@ -6,27 +6,27 @@
namespace Civi\ActionProvider\Utils;
class FileWriter {
class Files {
/**
* Write to a file in a restricted directory. E.g. a directory which is not accesible by
* a url.
* Creates a directory under templates_c/action_provider
* And adds a .htaccess to this directory so files could not be downloaded directly from the server.
*
* @param $contents
* @param $filename
* @param $subDir
* @param string $dir
* The subdirectory without / on the end. E.g. createpdf or createpdf/batch1233
* @return string
* The full file path.
*/
public static function writeFile($contents, $filename, $subDir) {
$basePath = \CRM_Core_Config::singleton()->templateCompileDir . $subDir;
\CRM_Utils_File::createDir($basePath);
\CRM_Utils_File::restrictAccess($basePath.'/');
$fullFilePath = $basePath.'/'. $filename;
public static function createRestrictedDirectory($dir) {
$subDir = 'action_provider/'.$dir;
$fullPath = \CRM_Core_Config::singleton()->templateCompileDir . $subDir;
if (is_dir($fullPath)) {
\CRM_Utils_File::restrictAccess($fullPath.'/');
return $subDir;
}
file_put_contents($fullFilePath, $contents);
return $fullFilePath;
\CRM_Utils_File::createDir($fullPath);
\CRM_Utils_File::restrictAccess($fullPath.'/');
return $subDir;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment