CRM-15832 - crmResource - Add module to load partials+strings in batches.
[civicrm-core.git] / CRM / Utils / File.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id: $
33 *
34 */
35
36/**
37 * class to provide simple static functions for file objects
38 */
39class CRM_Utils_File {
40
41 /**
42 * Given a file name, determine if the file contents make it an ascii file
43 *
77855840
TO
44 * @param string $name
45 * Name of file.
6a488035 46 *
ae5ffbb7 47 * @return bool
a6c01b45 48 * true if file is ascii
6a488035 49 */
00be9182 50 public static function isAscii($name) {
6a488035
TO
51 $fd = fopen($name, "r");
52 if (!$fd) {
53 return FALSE;
54 }
55
56 $ascii = TRUE;
57 while (!feof($fd)) {
58 $line = fgets($fd, 8192);
59 if (!CRM_Utils_String::isAscii($line)) {
60 $ascii = FALSE;
61 break;
62 }
63 }
64
65 fclose($fd);
66 return $ascii;
67 }
68
69 /**
70 * Given a file name, determine if the file contents make it an html file
71 *
77855840
TO
72 * @param string $name
73 * Name of file.
6a488035 74 *
ae5ffbb7 75 * @return bool
a6c01b45 76 * true if file is html
6a488035 77 */
00be9182 78 public static function isHtml($name) {
6a488035
TO
79 $fd = fopen($name, "r");
80 if (!$fd) {
81 return FALSE;
82 }
83
84 $html = FALSE;
85 $lineCount = 0;
86 while (!feof($fd) & $lineCount <= 5) {
87 $lineCount++;
88 $line = fgets($fd, 8192);
89 if (!CRM_Utils_String::isHtml($line)) {
90 $html = TRUE;
91 break;
92 }
93 }
94
95 fclose($fd);
96 return $html;
97 }
98
99 /**
100fef9d 100 * Create a directory given a path name, creates parent directories
6a488035
TO
101 * if needed
102 *
77855840
TO
103 * @param string $path
104 * The path name.
105 * @param bool $abort
106 * Should we abort or just return an invalid code.
6a488035
TO
107 *
108 * @return void
6a488035 109 */
00be9182 110 public static function createDir($path, $abort = TRUE) {
6a488035
TO
111 if (is_dir($path) || empty($path)) {
112 return;
113 }
114
115 CRM_Utils_File::createDir(dirname($path), $abort);
116 if (@mkdir($path, 0777) == FALSE) {
117 if ($abort) {
118 $docLink = CRM_Utils_System::docURL2('Moving an Existing Installation to a New Server or Location', NULL, NULL, NULL, NULL, "wiki");
119 echo "Error: Could not create directory: $path.<p>If you have moved an existing CiviCRM installation from one location or server to another there are several steps you will need to follow. They are detailed on this CiviCRM wiki page - {$docLink}. A fix for the specific problem that caused this error message to be displayed is to set the value of the config_backend column in the civicrm_domain table to NULL. However we strongly recommend that you review and follow all the steps in that document.</p>";
120
121 CRM_Utils_System::civiExit();
122 }
123 else {
124 return FALSE;
125 }
126 }
127 return TRUE;
128 }
129
130 /**
100fef9d 131 * Delete a directory given a path name, delete children directories
6a488035
TO
132 * and files if needed
133 *
77855840
TO
134 * @param string $target
135 * The path name.
f4aaa82a
EM
136 * @param bool $rmdir
137 * @param bool $verbose
138 *
139 * @throws Exception
6a488035 140 * @return void
6a488035 141 */
00be9182 142 public static function cleanDir($target, $rmdir = TRUE, $verbose = TRUE) {
6a488035
TO
143 static $exceptions = array('.', '..');
144 if ($target == '' || $target == '/') {
145 throw new Exception("Overly broad deletion");
146 }
147
5e7670b1 148 if ($dh = @opendir($target)) {
149 while (FALSE !== ($sibling = readdir($dh))) {
6a488035
TO
150 if (!in_array($sibling, $exceptions)) {
151 $object = $target . DIRECTORY_SEPARATOR . $sibling;
152
153 if (is_dir($object)) {
154 CRM_Utils_File::cleanDir($object, $rmdir, $verbose);
155 }
156 elseif (is_file($object)) {
157 if (!unlink($object)) {
158 CRM_Core_Session::setStatus(ts('Unable to remove file %1', array(1 => $object)), ts('Warning'), 'error');
e7292422 159 }
6a488035
TO
160 }
161 }
162 }
5e7670b1 163 closedir($dh);
6a488035
TO
164
165 if ($rmdir) {
166 if (rmdir($target)) {
167 if ($verbose) {
450f494d 168 CRM_Core_Session::setStatus(ts('Removed directory %1', array(1 => $target)), '', 'success');
6a488035
TO
169 }
170 return TRUE;
e7292422 171 }
6a488035
TO
172 else {
173 CRM_Core_Session::setStatus(ts('Unable to remove directory %1', array(1 => $target)), ts('Warning'), 'error');
e7292422
TO
174 }
175 }
6a488035
TO
176 }
177 }
178
5bc392e6 179 /**
ae5ffbb7
TO
180 * @param string $source
181 * @param string $destination
5bc392e6 182 */
ae5ffbb7 183 public static function copyDir($source, $destination) {
5e7670b1 184 if ($dh = opendir($source)) {
948d11bf 185 @mkdir($destination);
5e7670b1 186 while (FALSE !== ($file = readdir($dh))) {
948d11bf
CB
187 if (($file != '.') && ($file != '..')) {
188 if (is_dir($source . DIRECTORY_SEPARATOR . $file)) {
189 CRM_Utils_File::copyDir($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
190 }
191 else {
192 copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file);
193 }
6a488035
TO
194 }
195 }
5e7670b1 196 closedir($dh);
6a488035 197 }
6a488035
TO
198 }
199
200 /**
201 * Given a file name, recode it (in place!) to UTF-8
202 *
77855840
TO
203 * @param string $name
204 * Name of file.
6a488035 205 *
ae5ffbb7 206 * @return bool
a6c01b45 207 * whether the file was recoded properly
6a488035 208 */
00be9182 209 public static function toUtf8($name) {
6a488035
TO
210 static $config = NULL;
211 static $legacyEncoding = NULL;
212 if ($config == NULL) {
213 $config = CRM_Core_Config::singleton();
214 $legacyEncoding = $config->legacyEncoding;
215 }
216
217 if (!function_exists('iconv')) {
218
219 return FALSE;
220
221 }
222
223 $contents = file_get_contents($name);
224 if ($contents === FALSE) {
225 return FALSE;
226 }
227
228 $contents = iconv($legacyEncoding, 'UTF-8', $contents);
229 if ($contents === FALSE) {
230 return FALSE;
231 }
232
233 $file = fopen($name, 'w');
234 if ($file === FALSE) {
235 return FALSE;
236 }
237
238 $written = fwrite($file, $contents);
239 $closed = fclose($file);
240 if ($written === FALSE or !$closed) {
241 return FALSE;
242 }
243
244 return TRUE;
245 }
246
247 /**
5c8cb77f 248 * Appends a slash to the end of a string if it doesn't already end with one
6a488035 249 *
5c8cb77f
CW
250 * @param string $path
251 * @param string $slash
f4aaa82a 252 *
6a488035 253 * @return string
6a488035 254 */
00be9182 255 public static function addTrailingSlash($path, $slash = NULL) {
5c8cb77f
CW
256 if (!$slash) {
257 // FIXME: Defaulting to backslash on windows systems can produce unexpected results, esp for URL strings which should always use forward-slashes.
258 // I think this fn should default to forward-slash instead.
259 $slash = DIRECTORY_SEPARATOR;
6a488035 260 }
5c8cb77f
CW
261 if (!in_array(substr($path, -1, 1), array('/', '\\'))) {
262 $path .= $slash;
6a488035 263 }
5c8cb77f 264 return $path;
6a488035
TO
265 }
266
5bc392e6
EM
267 /**
268 * @param $dsn
100fef9d 269 * @param string $fileName
5bc392e6
EM
270 * @param null $prefix
271 * @param bool $isQueryString
272 * @param bool $dieOnErrors
273 */
00be9182 274 public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE) {
6a488035
TO
275 require_once 'DB.php';
276
277 $db = DB::connect($dsn);
278 if (PEAR::isError($db)) {
279 die("Cannot open $dsn: " . $db->getMessage());
280 }
281 if (CRM_Utils_Constant::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System::isDevelopment())) {
282 $db->query('SET SESSION sql_mode = STRICT_TRANS_TABLES');
283 }
284
285 if (!$isQueryString) {
286 $string = $prefix . file_get_contents($fileName);
287 }
288 else {
289 // use filename as query string
290 $string = $prefix . $fileName;
291 }
292
293 //get rid of comments starting with # and --
294
295 $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
296 $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
297
298 $queries = preg_split('/;\s*$/m', $string);
299 foreach ($queries as $query) {
300 $query = trim($query);
301 if (!empty($query)) {
302 CRM_Core_Error::debug_query($query);
303 $res = &$db->query($query);
304 if (PEAR::isError($res)) {
305 if ($dieOnErrors) {
306 die("Cannot execute $query: " . $res->getMessage());
307 }
308 else {
309 echo "Cannot execute $query: " . $res->getMessage() . "<p>";
310 }
311 }
312 }
313 }
314 }
315
5bc392e6
EM
316 /**
317 * @param $ext
318 *
319 * @return bool
320 */
00be9182 321 public static function isExtensionSafe($ext) {
6a488035
TO
322 static $extensions = NULL;
323 if (!$extensions) {
324 $extensions = CRM_Core_OptionGroup::values('safe_file_extension', TRUE);
325
326 //make extensions to lowercase
327 $extensions = array_change_key_case($extensions, CASE_LOWER);
328 // allow html/htm extension ONLY if the user is admin
329 // and/or has access CiviMail
330 if (!(CRM_Core_Permission::check('access CiviMail') ||
353ffa53
TO
331 CRM_Core_Permission::check('administer CiviCRM') ||
332 (CRM_Mailing_Info::workflowEnabled() &&
333 CRM_Core_Permission::check('create mailings')
334 )
335 )
336 ) {
6a488035
TO
337 unset($extensions['html']);
338 unset($extensions['htm']);
339 }
340 }
341 //support lower and uppercase file extensions
342 return isset($extensions[strtolower($ext)]) ? TRUE : FALSE;
343 }
344
345 /**
346 * Determine whether a given file is listed in the PHP include path
347 *
77855840
TO
348 * @param string $name
349 * Name of file.
6a488035 350 *
ae5ffbb7 351 * @return bool
a6c01b45 352 * whether the file can be include()d or require()d
6a488035 353 */
00be9182 354 public static function isIncludable($name) {
6a488035
TO
355 $x = @fopen($name, 'r', TRUE);
356 if ($x) {
357 fclose($x);
358 return TRUE;
359 }
360 else {
361 return FALSE;
362 }
363 }
364
365 /**
100fef9d 366 * Remove the 32 bit md5 we add to the fileName
6a488035
TO
367 * also remove the unknown tag if we added it
368 */
00be9182 369 public static function cleanFileName($name) {
6a488035
TO
370 // replace the last 33 character before the '.' with null
371 $name = preg_replace('/(_[\w]{32})\./', '.', $name);
372 return $name;
373 }
374
5bc392e6 375 /**
100fef9d 376 * @param string $name
5bc392e6
EM
377 *
378 * @return string
379 */
00be9182 380 public static function makeFileName($name) {
353ffa53
TO
381 $uniqID = md5(uniqid(rand(), TRUE));
382 $info = pathinfo($name);
6a488035
TO
383 $basename = substr($info['basename'],
384 0, -(strlen(CRM_Utils_Array::value('extension', $info)) + (CRM_Utils_Array::value('extension', $info) == '' ? 0 : 1))
385 );
386 if (!self::isExtensionSafe(CRM_Utils_Array::value('extension', $info))) {
387 // munge extension so it cannot have an embbeded dot in it
388 // The maximum length of a filename for most filesystems is 255 chars.
389 // We'll truncate at 240 to give some room for the extension.
390 return CRM_Utils_String::munge("{$basename}_" . CRM_Utils_Array::value('extension', $info) . "_{$uniqID}", '_', 240) . ".unknown";
391 }
392 else {
393 return CRM_Utils_String::munge("{$basename}_{$uniqID}", '_', 240) . "." . CRM_Utils_Array::value('extension', $info);
394 }
395 }
396
5bc392e6
EM
397 /**
398 * @param $path
399 * @param $ext
400 *
401 * @return array
402 */
00be9182 403 public static function getFilesByExtension($path, $ext) {
353ffa53 404 $path = self::addTrailingSlash($path);
6a488035 405 $files = array();
948d11bf 406 if ($dh = opendir($path)) {
948d11bf
CB
407 while (FALSE !== ($elem = readdir($dh))) {
408 if (substr($elem, -(strlen($ext) + 1)) == '.' . $ext) {
409 $files[] .= $path . $elem;
410 }
6a488035 411 }
948d11bf 412 closedir($dh);
6a488035 413 }
6a488035
TO
414 return $files;
415 }
416
417 /**
418 * Restrict access to a given directory (by planting there a restrictive .htaccess file)
419 *
77855840
TO
420 * @param string $dir
421 * The directory to be secured.
f4aaa82a 422 * @param bool $overwrite
6a488035 423 */
00be9182 424 public static function restrictAccess($dir, $overwrite = FALSE) {
6a488035
TO
425 // note: empty value for $dir can play havoc, since that might result in putting '.htaccess' to root dir
426 // of site, causing site to stop functioning.
427 // FIXME: we should do more checks here -
ea3b22b5 428 if (!empty($dir) && is_dir($dir)) {
6a488035
TO
429 $htaccess = <<<HTACCESS
430<Files "*">
431 Order allow,deny
432 Deny from all
433</Files>
434
435HTACCESS;
436 $file = $dir . '.htaccess';
ea3b22b5
TO
437 if ($overwrite || !file_exists($file)) {
438 if (file_put_contents($file, $htaccess) === FALSE) {
439 CRM_Core_Error::movedSiteError($file);
440 }
6a488035
TO
441 }
442 }
443 }
444
af5201d4
TO
445 /**
446 * Restrict remote users from browsing the given directory.
447 *
448 * @param $publicDir
449 */
00be9182 450 public static function restrictBrowsing($publicDir) {
9404eeac
TO
451 if (!is_dir($publicDir) || !is_writable($publicDir)) {
452 return;
453 }
454
af5201d4
TO
455 // base dir
456 $nobrowse = realpath($publicDir) . '/index.html';
457 if (!file_exists($nobrowse)) {
458 @file_put_contents($nobrowse, '');
459 }
460
461 // child dirs
462 $dir = new RecursiveDirectoryIterator($publicDir);
463 foreach ($dir as $name => $object) {
464 if (is_dir($name) && $name != '..') {
465 $nobrowse = realpath($name) . '/index.html';
466 if (!file_exists($nobrowse)) {
467 @file_put_contents($nobrowse, '');
468 }
469 }
470 }
471 }
472
6a488035
TO
473 /**
474 * Create the base file path from which all our internal directories are
475 * offset. This is derived from the template compile directory set
476 */
00be9182 477 public static function baseFilePath($templateCompileDir = NULL) {
6a488035
TO
478 static $_path = NULL;
479 if (!$_path) {
480 if ($templateCompileDir == NULL) {
481 $config = CRM_Core_Config::singleton();
482 $templateCompileDir = $config->templateCompileDir;
483 }
484
485 $path = dirname($templateCompileDir);
486
487 //this fix is to avoid creation of upload dirs inside templates_c directory
488 $checkPath = explode(DIRECTORY_SEPARATOR, $path);
489
490 $cnt = count($checkPath) - 1;
491 if ($checkPath[$cnt] == 'templates_c') {
492 unset($checkPath[$cnt]);
493 $path = implode(DIRECTORY_SEPARATOR, $checkPath);
494 }
495
496 $_path = CRM_Utils_File::addTrailingSlash($path);
497 }
498 return $_path;
499 }
500
5bc392e6
EM
501 /**
502 * @param $directory
503 *
504 * @return string
505 */
00be9182 506 public static function relativeDirectory($directory) {
6a488035
TO
507 // Do nothing on windows
508 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
509 return $directory;
510 }
511
512 // check if directory is relative, if so return immediately
513 if (substr($directory, 0, 1) != DIRECTORY_SEPARATOR) {
514 return $directory;
515 }
516
517 // make everything relative from the baseFilePath
518 $basePath = self::baseFilePath();
519 // check if basePath is a substr of $directory, if so
520 // return rest of string
521 if (substr($directory, 0, strlen($basePath)) == $basePath) {
522 return substr($directory, strlen($basePath));
523 }
524
525 // return the original value
526 return $directory;
527 }
528
5bc392e6
EM
529 /**
530 * @param $directory
531 *
532 * @return string
533 */
00be9182 534 public static function absoluteDirectory($directory) {
acc609a7
TO
535 // check if directory is already absolute, if so return immediately
536 // Note: Windows PHP accepts any mix of "/" or "\", so "C:\htdocs" or "C:/htdocs" would be a valid absolute path
537 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && preg_match(';^[a-zA-Z]:[/\\\\];', $directory)) {
6a488035
TO
538 return $directory;
539 }
540
541 // check if directory is already absolute, if so return immediately
542 if (substr($directory, 0, 1) == DIRECTORY_SEPARATOR) {
543 return $directory;
544 }
545
546 // make everything absolute from the baseFilePath
547 $basePath = self::baseFilePath();
548
549 return $basePath . $directory;
550 }
551
552 /**
553 * Make a file path relative to some base dir
554 *
f4aaa82a
EM
555 * @param $directory
556 * @param $basePath
557 *
6a488035
TO
558 * @return string
559 */
00be9182 560 public static function relativize($directory, $basePath) {
6a488035
TO
561 if (substr($directory, 0, strlen($basePath)) == $basePath) {
562 return substr($directory, strlen($basePath));
0db6c3e1
TO
563 }
564 else {
6a488035
TO
565 return $directory;
566 }
567 }
568
569 /**
570 * Create a path to a temporary file which can endure for multiple requests
571 *
572 * TODO: Automatic file cleanup using, eg, TTL policy
573 *
5a4f6742 574 * @param string $prefix
6a488035
TO
575 *
576 * @return string, path to an openable/writable file
577 * @see tempnam
578 */
00be9182 579 public static function tempnam($prefix = 'tmp-') {
6a488035
TO
580 //$config = CRM_Core_Config::singleton();
581 //$nonce = md5(uniqid() . $config->dsn . $config->userFrameworkResourceURL);
582 //$fileName = "{$config->configAndLogDir}" . $prefix . $nonce . $suffix;
583 $fileName = tempnam(sys_get_temp_dir(), $prefix);
584 return $fileName;
585 }
586
587 /**
588 * Create a path to a temporary directory which can endure for multiple requests
589 *
590 * TODO: Automatic file cleanup using, eg, TTL policy
591 *
5a4f6742 592 * @param string $prefix
6a488035
TO
593 *
594 * @return string, path to an openable/writable directory; ends with '/'
595 * @see tempnam
596 */
00be9182 597 public static function tempdir($prefix = 'tmp-') {
6a488035
TO
598 $fileName = self::tempnam($prefix);
599 unlink($fileName);
600 mkdir($fileName, 0700);
601 return $fileName . '/';
602 }
603
604 /**
d7166b43
TO
605 * Search directory tree for files which match a glob pattern.
606 *
607 * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
6a488035 608 *
5a4f6742
CW
609 * @param string $dir
610 * base dir.
611 * @param string $pattern
612 * glob pattern, eg "*.txt".
a2dc0f82
TO
613 * @param bool $relative
614 * TRUE if paths should be made relative to $dir
6a488035
TO
615 * @return array(string)
616 */
a2dc0f82
TO
617 public static function findFiles($dir, $pattern, $relative = FALSE) {
618 $dir = rtrim($dir, '/');
6a488035
TO
619 $todos = array($dir);
620 $result = array();
621 while (!empty($todos)) {
622 $subdir = array_shift($todos);
0b72a00f
TO
623 $matches = glob("$subdir/$pattern");
624 if (is_array($matches)) {
625 foreach ($matches as $match) {
002f1716 626 if (!is_dir($match)) {
a2dc0f82 627 $result[] = $relative ? CRM_Utils_File::relativize($match, "$dir/") : $match;
002f1716 628 }
6a488035
TO
629 }
630 }
948d11bf 631 if ($dh = opendir($subdir)) {
6a488035
TO
632 while (FALSE !== ($entry = readdir($dh))) {
633 $path = $subdir . DIRECTORY_SEPARATOR . $entry;
d7166b43
TO
634 if ($entry{0} == '.') {
635 // ignore
0db6c3e1
TO
636 }
637 elseif (is_dir($path)) {
6a488035
TO
638 $todos[] = $path;
639 }
640 }
641 closedir($dh);
642 }
643 }
644 return $result;
645 }
646
647 /**
648 * Determine if $child is a sub-directory of $parent
649 *
650 * @param string $parent
651 * @param string $child
f4aaa82a
EM
652 * @param bool $checkRealPath
653 *
6a488035
TO
654 * @return bool
655 */
00be9182 656 public static function isChildPath($parent, $child, $checkRealPath = TRUE) {
6a488035
TO
657 if ($checkRealPath) {
658 $parent = realpath($parent);
659 $child = realpath($child);
660 }
661 $parentParts = explode('/', rtrim($parent, '/'));
662 $childParts = explode('/', rtrim($child, '/'));
663 while (($parentPart = array_shift($parentParts)) !== NULL) {
664 $childPart = array_shift($childParts);
665 if ($parentPart != $childPart) {
666 return FALSE;
667 }
668 }
669 if (empty($childParts)) {
670 return FALSE; // same directory
0db6c3e1
TO
671 }
672 else {
6a488035
TO
673 return TRUE;
674 }
675 }
676
677 /**
678 * Move $fromDir to $toDir, replacing/deleting any
679 * pre-existing content.
680 *
77855840
TO
681 * @param string $fromDir
682 * The directory which should be moved.
683 * @param string $toDir
684 * The new location of the directory.
f4aaa82a
EM
685 * @param bool $verbose
686 *
a6c01b45
CW
687 * @return bool
688 * TRUE on success
6a488035 689 */
00be9182 690 public static function replaceDir($fromDir, $toDir, $verbose = FALSE) {
6a488035
TO
691 if (is_dir($toDir)) {
692 if (!self::cleanDir($toDir, TRUE, $verbose)) {
693 return FALSE;
694 }
695 }
696
697 // return rename($fromDir, $toDir); // CRM-11987, https://bugs.php.net/bug.php?id=54097
698
699 CRM_Utils_File::copyDir($fromDir, $toDir);
700 if (!CRM_Utils_File::cleanDir($fromDir, TRUE, FALSE)) {
e7292422 701 CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $fromDir)), '', 'alert');
6a488035
TO
702 return FALSE;
703 }
704 return TRUE;
705 }
706}