/** * Copy folder to cloud storage * * @param string $sourcePath * @param string $destPath * @param array $fileTypes * @param int $level * * @return boolean */ public function copyDir($sourcePath, $destPath, array $fileTypes = null, $level = -1) { $sourcePath = UTIL_File::removeLastDS($sourcePath); $destPath = UTIL_File::removeLastDS($destPath); if (!UTIL_File::checkDir($sourcePath)) { return false; } if (!$this->fileExists($destPath)) { $this->mkdir($destPath); } $handle = opendir($sourcePath); while (($item = readdir($handle)) !== false) { if ($item === '.' || $item === '..' || $item === '') { continue; } $path = $sourcePath . DS . $item; $dPath = $destPath . DS . $item; if (is_file($path)) { if ($fileTypes === null || in_array(UTIL_File::getExtension($path), $fileTypes)) { $this->copyFile($path, $dPath); } } else { if ($level && is_dir($path)) { $this->copyDir($path, $dPath, $fileTypes, $level - 1); } } } closedir($handle); return true; }
/** * @param string $path * @param bool $refreshCache * @param bool $addLanguage * @param bool $updateValues */ public function importPrefixFromDir($path, $refreshCache = true, $addLanguage = false, $updateValues = false) { $path = UTIL_File::removeLastDS($path) . DS; if (!UTIL_File::checkDir($path)) { throw new InvalidArgumentException("Directory not found : {$path}"); } $arr = glob("{$path}*"); $prefixesToImport = array(); $langsToImport = array(); foreach ($arr as $index => $dir) { $dh = opendir($dir); if (!file_exists($dir . DS . 'language.xml')) { continue; } $langXmlE = simplexml_load_file($dir . DS . 'language.xml'); $l = array('label' => strval($langXmlE->attributes()->label), 'tag' => strval($langXmlE->attributes()->tag), 'path' => $dir . DS); if (!in_array($l, $langsToImport)) { $langsToImport[] = $l; } /* @var $xmlElement SimpleXMLElement */ while (false !== ($file = readdir($dh))) { if ($file == '.' || $file == '..' || is_dir($dir . DS . $file) || $file == 'language.xml' || !file_exists($dir . DS . $file)) { continue; } $xmlElement = simplexml_load_file($dir . DS . $file); $tmp = $xmlElement->xpath('/prefix'); $prefixElement = $tmp[0]; $prefixItem = array('label' => strval($prefixElement->attributes()->label), 'prefix' => strval($prefixElement->attributes()->name)); if (!in_array($prefixItem, $prefixesToImport)) { $prefixesToImport[] = $prefixItem; } } } $languages = $this->getLanguages(); $activateFirstLang = empty($languages); foreach ($langsToImport as $langToImport) { if (!$this->findByTag($langToImport['tag'])) { if (!$addLanguage) { continue; } $dto = new BOL_Language(); $dto->setLabel($langToImport['label'])->setTag($langToImport['tag'])->setStatus($activateFirstLang ? 'active' : 'inactive')->setOrder($this->findMaxOrder() + 1); $this->save($dto); $activateFirstLang = false; } foreach ($prefixesToImport as $prefixToImport) { $filePath = $langToImport['path'] . "{$prefixToImport['prefix']}.xml"; if (!file_exists($filePath)) { continue; } $xml = simplexml_load_file($filePath); $this->importPrefix($xml, false, false, $updateValues); } } if ($refreshCache) { $this->generateCacheForAllActiveLanguages(); } }