当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_File::cleanDir方法代码示例

本文整理汇总了PHP中CRM_Utils_File::cleanDir方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_File::cleanDir方法的具体用法?PHP CRM_Utils_File::cleanDir怎么用?PHP CRM_Utils_File::cleanDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_File的用法示例。


在下文中一共展示了CRM_Utils_File::cleanDir方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cleanup

 /**
  * Deletes the web server writable directories.
  *
  * @param int $value
  *   1: clean templates_c, 2: clean upload, 3: clean both
  * @param bool $rmdir
  */
 public function cleanup($value, $rmdir = TRUE)
 {
     $value = (int) $value;
     if ($value & 1) {
         // clean templates_c
         CRM_Utils_File::cleanDir($this->templateCompileDir, $rmdir);
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if ($value & 2) {
         // clean upload dir
         CRM_Utils_File::cleanDir($this->uploadDir);
         CRM_Utils_File::createDir($this->uploadDir);
     }
     // Whether we delete/create or simply preserve directories, we should
     // certainly make sure the restrictions are enforced.
     foreach (array($this->templateCompileDir, $this->uploadDir, $this->configAndLogDir, $this->customFileUploadDir) as $dir) {
         if ($dir && is_dir($dir)) {
             CRM_Utils_File::restrictAccess($dir);
         }
     }
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:28,代码来源:Config.php

示例2: testReplace_InstalledMissing

 /**
  * Install a module and then delete (leaving stale DB info); restore
  * the module by downloading new code.
  *
  * Note that some metadata changes between versions -- the original has
  * file="oddball", and the upgrade has file="newextension".
  */
 public function testReplace_InstalledMissing()
 {
     $testingTypeManager = $this->getMock('CRM_Extension_Manager_Interface');
     $manager = $this->_createManager(array(self::TESTING_TYPE => $testingTypeManager));
     // initial installation
     $this->assertEquals('uninstalled', $manager->getStatus('test.whiz.bang'));
     $manager->install(array('test.whiz.bang'));
     $this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
     // dirty remove
     $this->assertTrue(file_exists("{$this->basedir}/weird/whizbang/info.xml"));
     CRM_Utils_File::cleanDir("{$this->basedir}/weird/whizbang", TRUE, FALSE);
     $this->assertFalse(file_exists("{$this->basedir}/weird/whizbang/info.xml"));
     $manager->refresh();
     $this->assertEquals('installed-missing', $manager->getStatus('test.whiz.bang'));
     // download and reinstall
     $this->download = $this->_createDownload('test.whiz.bang', 'newextension');
     $testingTypeManager->expects($this->once())->method('onPreReplace');
     $testingTypeManager->expects($this->once())->method('onPostReplace');
     $manager->replace($this->download);
     $this->assertEquals('installed', $manager->getStatus('test.whiz.bang'));
     $this->assertTrue(file_exists("{$this->basedir}/test.whiz.bang/info.xml"));
     $this->assertTrue(file_exists("{$this->basedir}/test.whiz.bang/newextension.php"));
     $this->assertEquals('newextension', $this->mapper->keyToInfo('test.whiz.bang')->file);
     $this->assertDBQuery('newextension', 'SELECT file FROM civicrm_extension WHERE full_name ="test.whiz.bang"');
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:32,代码来源:ManagerTest.php

示例3: testInstall_DirtyRemove_Disable_Restore

 /**
  * Install an extension then forcibly remove the code and cleanup DB afterwards.
  */
 public function testInstall_DirtyRemove_Disable_Restore()
 {
     // create temporary extension (which can dirtily remove later)
     $this->_createExtension('test.extension.manager.module.auto2', 'module', 'test_extension_manager_module_auto2');
     $mainfile = $this->basedir . '/test.extension.manager.module.auto2/test_extension_manager_module_auto2.php';
     $this->assertTrue(file_exists($mainfile));
     $manager = $this->system->getManager();
     $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2');
     $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto2');
     // install it
     $manager->install(array('test.extension.manager.module.auto2'));
     $this->assertEquals('installed', $manager->getStatus('test.extension.manager.module.auto2'));
     $this->assertHookCounts('test_extension_manager_module_auto2', array('install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0));
     $this->assertModuleActiveByName(TRUE, 'test_extension_manager_module_auto2');
     $this->assertModuleActiveByKey(TRUE, 'test.extension.manager.module.auto2');
     // dirty removal
     CRM_Utils_File::cleanDir($this->basedir . '/test.extension.manager.module.auto2', TRUE, FALSE);
     $manager->refresh();
     $this->assertEquals('installed-missing', $manager->getStatus('test.extension.manager.module.auto2'));
     // disable while missing
     $manager->disable(array('test.extension.manager.module.auto2'));
     $this->assertEquals('disabled-missing', $manager->getStatus('test.extension.manager.module.auto2'));
     $this->assertHookCounts('test_extension_manager_module_auto2', array('install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0));
     $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2');
     $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.moduletest');
     // restore the code
     $this->_createExtension('test.extension.manager.module.auto2', 'module', 'test_extension_manager_module_auto2');
     $manager->refresh();
     $this->assertHookCounts('test_extension_manager_module_auto2', array('install' => 1, 'enable' => 1, 'disable' => 0, 'uninstall' => 0));
     $this->assertEquals('disabled', $manager->getStatus('test.extension.manager.module.auto2'));
     $this->assertModuleActiveByName(FALSE, 'test_extension_manager_module_auto2');
     $this->assertModuleActiveByKey(FALSE, 'test.extension.manager.module.auto2');
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:36,代码来源:ModuleTest.php

示例4: cleanDir

 /** 
  * delete a directory given a path name, delete children directories
  * and files if needed 
  *  
  * @param string $path  the path name 
  * 
  * @return void 
  * @access public 
  * @static 
  */
 public function cleanDir($target, $rmdir = true)
 {
     static $exceptions = array('.', '..');
     if ($sourcedir = @opendir($target)) {
         while (false !== ($sibling = readdir($sourcedir))) {
             if (!in_array($sibling, $exceptions)) {
                 $object = $target . DIRECTORY_SEPARATOR . $sibling;
                 if (is_dir($object)) {
                     CRM_Utils_File::cleanDir($object, $rmdir);
                 } else {
                     if (is_file($object)) {
                         $result = @unlink($object);
                     }
                 }
             }
         }
         closedir($sourcedir);
         if ($rmdir) {
             $result = @rmdir($target);
         }
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:32,代码来源:File.php

示例5: cleanup

 /**
  * delete the web server writable directories
  *
  * @param int $value 1 - clean templates_c, 2 - clean upload, 3 - clean both
  *
  * @access public
  * @return void
  */
 public function cleanup($value)
 {
     $value = (int) $value;
     if ($value & 1) {
         // clean templates_c
         CRM_Utils_File::cleanDir($this->templateCompileDir);
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if ($value & 2) {
         // clean upload dir
         CRM_Utils_File::cleanDir($this->uploadDir);
         CRM_Utils_File::createDir($this->uploadDir);
     }
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:22,代码来源:Config.php

示例6: extractFiles

 /**
  * Extract an extension from a zip file.
  *
  * @param string $key
  *   The name of the extension being installed; this usually matches the basedir in the .zip.
  * @param string $zipFile
  *   The local path to a .zip file.
  * @return string|FALSE
  *   zip file path
  */
 public function extractFiles($key, $zipFile)
 {
     $config = CRM_Core_Config::singleton();
     $zip = new ZipArchive();
     $res = $zip->open($zipFile);
     if ($res === TRUE) {
         $zipSubDir = CRM_Utils_Zip::guessBasedir($zip, $key);
         if ($zipSubDir === FALSE) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension: bad directory structure'), '', 'error');
             return FALSE;
         }
         $extractedZipPath = $this->tmpDir . DIRECTORY_SEPARATOR . $zipSubDir;
         if (is_dir($extractedZipPath)) {
             if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
                 CRM_Core_Session::setStatus(ts('Unable to extract the extension: %1 cannot be cleared', array(1 => $extractedZipPath)), ts('Installation Error'), 'error');
                 return FALSE;
             }
         }
         if (!$zip->extractTo($this->tmpDir)) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension to %1.', array(1 => $this->tmpDir)), ts('Installation Error'), 'error');
             return FALSE;
         }
         $zip->close();
     } else {
         CRM_Core_Session::setStatus(ts('Unable to extract the extension.'), '', 'error');
         return FALSE;
     }
     return $extractedZipPath;
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:39,代码来源:Downloader.php

示例7: replaceDir

 /**
  * Move $fromDir to $toDir, replacing/deleting any
  * pre-existing content.
  *
  * @param string $fromDir
  *   The directory which should be moved.
  * @param string $toDir
  *   The new location of the directory.
  * @param bool $verbose
  *
  * @return bool
  *   TRUE on success
  */
 public static function replaceDir($fromDir, $toDir, $verbose = FALSE)
 {
     if (is_dir($toDir)) {
         if (!self::cleanDir($toDir, TRUE, $verbose)) {
             return FALSE;
         }
     }
     // return rename($fromDir, $toDir); CRM-11987, https://bugs.php.net/bug.php?id=54097
     CRM_Utils_File::copyDir($fromDir, $toDir);
     if (!CRM_Utils_File::cleanDir($fromDir, TRUE, FALSE)) {
         CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $fromDir)), '', 'alert');
         return FALSE;
     }
     return TRUE;
 }
开发者ID:routinet,项目名称:civicrm-core,代码行数:28,代码来源:File.php

示例8: cleanTempDirs

 public function cleanTempDirs()
 {
     if (!is_array($this->tempDirs)) {
         // fix test errors where this is not set
         return;
     }
     foreach ($this->tempDirs as $tempDir) {
         if (is_dir($tempDir)) {
             CRM_Utils_File::cleanDir($tempDir, TRUE, FALSE);
         }
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:12,代码来源:CiviUnitTestCase.php

示例9: deleteFiles

 public function deleteFiles($id, $key)
 {
     require_once 'CRM/Utils/File.php';
     $e = self::$_extensions;
     CRM_Utils_File::cleanDir($e['per_id'][$id]['path']);
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:6,代码来源:ExtensionType.php

示例10: cleanDir

 /**
  * delete a directory given a path name, delete children directories
  * and files if needed
  *
  * @param string $path  the path name
  *
  * @return void
  * @access public
  * @static
  */
 public static function cleanDir($target, $rmdir = TRUE, $verbose = TRUE)
 {
     static $exceptions = array('.', '..');
     if ($target == '' || $target == '/') {
         throw new Exception("Overly broad deletion");
     }
     if ($sourcedir = @opendir($target)) {
         while (FALSE !== ($sibling = readdir($sourcedir))) {
             if (!in_array($sibling, $exceptions)) {
                 $object = $target . DIRECTORY_SEPARATOR . $sibling;
                 if (is_dir($object)) {
                     CRM_Utils_File::cleanDir($object, $rmdir);
                 } elseif (is_file($object)) {
                     if (!unlink($object)) {
                         CRM_Core_Session::setStatus(ts('Unable to remove file %1', array(1 => $object)) . '<br/>');
                     }
                 }
             }
         }
         closedir($sourcedir);
         if ($rmdir) {
             if (rmdir($target)) {
                 if ($verbose) {
                     CRM_Core_Session::setStatus(ts('Removed directory %1', array(1 => $target)) . '<br/>');
                 }
                 return TRUE;
             } else {
                 CRM_Core_Session::setStatus(ts('Unable to remove directory %1', array(1 => $target)) . '<br/>');
             }
         }
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:42,代码来源:File.php

示例11: cleanDir

 /** 
  * delete a directory given a path name, delete children directories
  * and files if needed 
  *  
  * @param string $path  the path name 
  * 
  * @return void 
  * @access public 
  * @static 
  */
 function cleanDir($target)
 {
     if ($sourcedir = @opendir($target)) {
         while (false !== ($sibling = readdir($sourcedir))) {
             if (!in_array($sibling, $GLOBALS['_CRM_UTILS_FILE']['exceptions'])) {
                 $object = $target . DIRECTORY_SEPARATOR . $sibling;
                 if (is_dir($object)) {
                     CRM_Utils_File::cleanDir($object);
                 } else {
                     if (is_file($object)) {
                         $result = @unlink($object);
                     }
                 }
             }
         }
         closedir($sourcedir);
         $result = @rmdir($target);
     }
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:29,代码来源:File.php

示例12: installFiles

 public function installFiles()
 {
     $config = CRM_Core_Config::singleton();
     $zip = new ZipArchive();
     $res = $zip->open($this->tmpFile);
     if ($res === TRUE) {
         $zipSubDir = CRM_Utils_Zip::guessBasedir($zip, $this->key);
         if ($zipSubDir === FALSE) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension: bad directory structure') . '<br/>');
             return FALSE;
         }
         $path = $config->extensionsDir . DIRECTORY_SEPARATOR . 'tmp';
         $extractedZipPath = $path . DIRECTORY_SEPARATOR . $zipSubDir;
         if (is_dir($extractedZipPath)) {
             if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
                 CRM_Core_Session::setStatus(ts('Unable to extract the extension: %1 cannot be cleared', array(1 => $extractedZipPath)) . '<br/>');
                 return FALSE;
             }
         }
         if (!$zip->extractTo($path)) {
             CRM_Core_Session::setStatus(ts('Unable to extract the extension to %1.', array(1 => $path)) . '<br/>');
             return FALSE;
         }
         $zip->close();
     } else {
         CRM_Core_Session::setStatus('Unable to extract the extension.');
         return FALSE;
     }
     $filename = $extractedZipPath . DIRECTORY_SEPARATOR . 'info.xml';
     if (!is_readable($filename)) {
         CRM_Core_Session::setStatus(ts('Failed reading data from %1 during installation', array(1 => $filename)) . '<br/>');
         return FALSE;
     }
     $newxml = file_get_contents($filename);
     if (empty($newxml)) {
         CRM_Core_Session::setStatus(ts('Failed reading data from %1 during installation', array(1 => $filename)) . '<br/>');
         return FALSE;
     }
     $check = new CRM_Core_Extensions_Extension($this->key . ".newversion");
     $check->readXMLInfo($newxml);
     if ($check->version != $this->version) {
         CRM_Core_Error::fatal('Cannot install - there are differences between extdir XML file and archive XML file!');
     }
     // Why is this a copy instead of a move?
     CRM_Utils_File::copyDir($extractedZipPath, $config->extensionsDir . DIRECTORY_SEPARATOR . $this->key);
     if (!CRM_Utils_File::cleanDir($extractedZipPath, TRUE, FALSE)) {
         CRM_Core_Session::setStatus(ts('Failed to clean temp dir: %1', array(1 => $extractedZipPath)) . '<br/>');
     }
     return TRUE;
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:50,代码来源:Extension.php

示例13: cleanup

 /**
  * delete the web server writable directories
  *
  * @param int $value 1 - clean templates_c, 2 - clean upload, 3 - clean both
  *
  * @access public
  *
  * @return void
  */
 public function cleanup($value, $rmdir = TRUE)
 {
     $value = (int) $value;
     if ($value & 1) {
         // clean templates_c
         CRM_Utils_File::cleanDir($this->templateCompileDir, $rmdir);
         CRM_Utils_File::createDir($this->templateCompileDir);
     }
     if ($value & 2) {
         // clean upload dir
         CRM_Utils_File::cleanDir($this->uploadDir);
         CRM_Utils_File::createDir($this->uploadDir);
         CRM_Utils_File::restrictAccess($this->uploadDir);
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:24,代码来源:Config.php

示例14: barGraph

 /**
  * Build The Bar Gharph image with given params 
  * and store in upload/pChart directory.
  *
  * @param  array  $params    an assoc array of name/value pairs          
  * @return array  $filesPath created image files Path.
  *
  * @static
  */
 static function barGraph($params, $divisionWidth = 44)
 {
     if (empty($params)) {
         return;
     }
     //get the required directory path.
     $config =& CRM_Core_Config::singleton();
     //get the default currency.
     $currency = $config->defaultCurrency;
     $pChartPath = str_replace('templates', 'packages', $config->templateDir);
     $pChartPath .= 'pChart/Fonts/';
     $uploadDirURL = str_replace('persist/contribute/', 'upload/pChart/', $config->imageUploadURL);
     $uploadDirPath = $config->uploadDir . 'pChart/';
     //create pchart directory, if exist clean and then create again.
     if (is_dir($uploadDirPath)) {
         CRM_Utils_File::cleanDir($uploadDirPath);
         CRM_Utils_File::createDir($uploadDirPath);
     } else {
         CRM_Utils_File::createDir($uploadDirPath);
     }
     require_once 'packages/pChart/pData.class.php';
     require_once 'packages/pChart/pChart.class.php';
     $chartCount = 0;
     $filesValues = array();
     foreach ($params as $chartIndex => $chartValues) {
         $chartCount++;
         $shades = 0;
         $names = $values = array();
         foreach ($chartValues['values'] as $indexName => $indexValue) {
             $names[] = $indexName;
             $values[] = $indexValue;
             $shades++;
         }
         $legend = CRM_Utils_Array::value('legend', $chartValues);
         $xname = CRM_Utils_Array::value('xname', $chartValues);
         $yname = CRM_Utils_Array::value('yname', $chartValues);
         //calculate max scale for graph.
         $maxScale = ceil(max($values) * 1.1);
         $fontSize = 8;
         $angleOfIncline = 45;
         $monetaryformatting = true;
         require_once 'CRM/Utils/Money.php';
         $formatedMoney = CRM_Utils_Money::format(max($values));
         $positions = imageftbbox($fontSize, 0, $pChartPath . "tahoma.ttf", $formatedMoney);
         $scaleTextWidth = $positions[2] - $positions[0];
         //need to increase Ysize if we incline money value.
         $increaseYBy = 0;
         $inclinePositions = imageftbbox($fontSize, $angleOfIncline, $pChartPath . "tahoma.ttf", $formatedMoney);
         $inclineTextWidth = $inclinePositions[2] - $inclinePositions[0];
         if ($inclineTextWidth > $divisionWidth) {
             $increaseYBy = $inclineTextWidth / 2;
         }
         //Initialise the co-ordinates.
         $xComponent = 20;
         $yComponent = 35;
         $ySize = 300;
         //calculate coords.
         $x1 = $xComponent + $scaleTextWidth;
         $y1 = $yComponent + $increaseYBy;
         $ySize += $increaseYBy;
         $y2 = $ySize - $yComponent;
         //calculate x axis size as per number of months.
         $x2 = $xComponent + $divisionWidth + $scaleTextWidth + (count($chartValues['values']) - 1) * $divisionWidth;
         $xSize = $x2 + $xComponent;
         $dataSet = new pData();
         $dataSet->AddPoint($values, "Serie1");
         $dataSet->AddPoint($names, "Serie2");
         $dataSet->AddSerie("Serie1");
         $dataSet->SetAbsciseLabelSerie("Serie2");
         //Initialise the graph
         $chart = new pChart($xSize, $ySize);
         $chart->setFontProperties($pChartPath . "tahoma.ttf", $fontSize);
         $chart->setGraphArea($x1, $y1, $x2, $y2);
         //set the y axis scale.
         $chart->setFixedScale(0, $maxScale, 1);
         $chart->drawFilledRoundedRectangle(0, 0, $xSize, $ySize, 5, 240, 240, 240);
         $chart->drawRoundedRectangle(0, 0, $xSize, $ySize, 5, 230, 230, 230);
         $chart->drawGraphArea(255, 255, 255, TRUE);
         $chart->drawScale($dataSet->GetData(), $dataSet->GetDataDescription(), SCALE_NORMAL, 150, 150, 150, TRUE, 0, 2, TRUE, 1, FALSE, $divisionWidth, $monetaryformatting);
         $chart->drawGrid(4, TRUE, 230, 230, 230, 50);
         //set colors.
         $chart->setColorShades($shades, self::$_colors);
         //Draw the bar chart
         $chart->drawBarGraph($dataSet->GetData(), $dataSet->GetDataDescription(), TRUE, 80, true);
         //get the series values and write at top.
         $chart->setColorPalette(0, 0, 0, 255);
         $dataDesc = $dataSet->GetDataDescription();
         $chart->writeValues($dataSet->GetData(), $dataSet->GetDataDescription(), $dataDesc['Values'], $monetaryformatting, $angleOfIncline);
         //Write the title
         if ($legend) {
             $chart->setFontProperties($pChartPath . "tahoma.ttf", 10);
//.........这里部分代码省略.........
开发者ID:ksecor,项目名称:civicrm,代码行数:101,代码来源:PChart.php


注:本文中的CRM_Utils_File::cleanDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。