/** * @return mixed */ public function getRealPath() { if (!$this->_realPath) { $this->_realPath = IOHelper::getRealPath($this->path); } return $this->_realPath; }
/** * @param $source * @param $destZip * * @return bool 'true' if the zip was successfully created, 'false' if not. */ public static function compress($source, $destZip) { $source = IOHelper::normalizePathSeparators($source); $destZip = IOHelper::normalizePathSeparators($destZip); if (!IOHelper::folderExists($source) && !IOHelper::fileExists($destZip)) { Craft::log('Tried to zip the contents of ' . $source . ' to ' . $destZip . ', but the source path does not exist.', LogLevel::Error); return false; } if (IOHelper::fileExists($destZip)) { IOHelper::deleteFile($destZip); } IOHelper::createFile($destZip); craft()->config->maxPowerCaptain(); $zip = static::_getZipInstance($destZip); return $zip->zip(IOHelper::getRealPath($source), IOHelper::getRealPath($destZip)); }
/** * @static * * @param $manifestData * @param $sourceTempFolder * @return bool * @return bool */ public static function doFileUpdate($manifestData, $sourceTempFolder) { try { foreach ($manifestData as $row) { if (static::isManifestVersionInfoLine($row)) { continue; } $folder = false; $rowData = explode(';', $row); if (static::isManifestLineAFolder($rowData[0])) { $folder = true; $tempPath = static::cleanManifestFolderLine($rowData[0]); } else { $tempPath = $rowData[0]; } $destFile = IOHelper::normalizePathSeparators(craft()->path->getAppPath() . $tempPath); $sourceFile = IOHelper::getRealPath(IOHelper::normalizePathSeparators($sourceTempFolder . '/app/' . $tempPath)); switch (trim($rowData[1])) { // update the file case PatchManifestFileAction::Add: if ($folder) { Craft::log('Updating folder: ' . $destFile, LogLevel::Info, true); $tempFolder = rtrim($destFile, '/') . StringHelper::UUID() . '/'; $tempTempFolder = rtrim($destFile, '/') . '-tmp/'; IOHelper::createFolder($tempFolder); IOHelper::copyFolder($sourceFile, $tempFolder); IOHelper::rename($destFile, $tempTempFolder); IOHelper::rename($tempFolder, $destFile); IOHelper::clearFolder($tempTempFolder); IOHelper::deleteFolder($tempTempFolder); } else { Craft::log('Updating file: ' . $destFile, LogLevel::Info, true); IOHelper::copyFile($sourceFile, $destFile); } break; } } } catch (\Exception $e) { Craft::log('Error updating files: ' . $e->getMessage(), LogLevel::Error); UpdateHelper::rollBackFileChanges($manifestData); return false; } return true; }
/** * Checks to see if Craft can write to a defined set of folders/files that are needed for auto-update to work. * * @return array|null */ public function getUnwritableFolders() { $checkPaths = array(craft()->path->getAppPath(), craft()->path->getPluginsPath()); $errorPath = null; foreach ($checkPaths as $writablePath) { if (!IOHelper::isWritable($writablePath)) { $errorPath[] = IOHelper::getRealPath($writablePath); } } return $errorPath; }
/** * Get the file system path for upload source. * * @param LocalAssetSourceType $sourceType The SourceType. * * @return string */ protected function getSourceFileSystemPath(LocalAssetSourceType $sourceType = null) { $path = is_null($sourceType) ? $this->getBasePath() : $sourceType->getBasePath(); $path = IOHelper::getRealPath($path); return $path; }
/** * Get paths for an external file (really external, or on an external source type) * * @param $image * @throws Exception */ private function _getPathsForUrl($image) { $urlParts = parse_url($image); $pathParts = pathinfo($urlParts['path']); $hashRemoteUrl = craft()->imager->getSetting('hashRemoteUrl'); if ($hashRemoteUrl) { if (is_string($hashRemoteUrl) && $hashRemoteUrl == 'host') { $parsedDirname = substr(md5($urlParts['host']), 0, 10) . $pathParts['dirname']; } else { $parsedDirname = md5($urlParts['host'] . $pathParts['dirname']); } } else { $parsedDirname = str_replace('.', '_', $urlParts['host']) . $pathParts['dirname']; } $this->sourcePath = craft()->path->getRuntimePath() . 'imager/' . $parsedDirname . '/'; $this->targetPath = craft()->imager->getSetting('imagerSystemPath') . $parsedDirname . '/'; $this->targetUrl = craft()->imager->getSetting('imagerUrl') . $parsedDirname . '/'; $this->sourceFilename = $this->targetFilename = $pathParts['basename']; // check if the temp path for remote files exists or can be created. if (!IOHelper::getRealPath($this->sourcePath)) { IOHelper::createFolder($this->sourcePath, craft()->config->get('defaultFolderPermissions'), true); if (!IOHelper::getRealPath($this->sourcePath)) { throw new Exception(Craft::t('Temp folder “{sourcePath}” does not exist and could not be created', array('sourcePath' => $this->sourcePath))); } } // check if the file is already downloaded if (!IOHelper::fileExists($this->sourcePath . $this->sourceFilename) || IOHelper::getLastTimeModified($this->sourcePath . $this->sourceFilename)->format('U') + craft()->imager->getSetting('cacheDurationRemoteFiles') < time()) { $this->_downloadFile($this->sourcePath . $this->sourceFilename, $image); if (!IOHelper::fileExists($this->sourcePath . $this->sourceFilename)) { throw new Exception(Craft::t('File could not be downloaded and saved to “{sourcePath}”', array('sourcePath' => $this->sourcePath))); } } }
/** * Looks for the template under the specified directory. * * @access protected * @param string $templatePath the folder containing the views * @param string $templateName template name (either 'exception' or 'error') * @param integer $code HTTP status code * @param string $type A string description of the type of error. * @param string $srcLanguage the language that the template is in * * @return string template path */ protected function getViewFileInternal($templatePath, $templateName, $code, $type, $srcLanguage = null) { if (strpos($templatePath, '/framework/') !== false) { $extension = 'php'; } else { $extension = 'html'; // Grab the numeric template from the code unless we're looking in the "_special" directory and it's not a Twig template syntax error if ($code && is_numeric($code) && strpos($templateName, '_special') === false && $type != 'Template Syntax Error') { // If it's a 200 HttpException, use the error template. if ((string) $code == '200') { $templateName = 'error'; } else { $templateName = (string) $code; } } } if ($templateName == 'error') { if (!empty($code)) { $templateFile = craft()->findLocalizedFile(IOHelper::getRealPath($templatePath . '/' . $templateName . '.' . $extension), $srcLanguage); if (IOHelper::fileExists($templateFile)) { return IOHelper::getRealPath($templateFile); } return null; } } $templateFile = craft()->findLocalizedFile(IOHelper::getRealPath($templatePath . '/' . $templateName . '.' . $extension), $srcLanguage); if (IOHelper::fileExists($templateFile)) { $templateFile = IOHelper::getRealPath($templateFile); } return $templateFile; }
/** */ public function run() { $this->init(); $installResult = InstallStatus::Success; foreach ($this->_requirements as $requirement) { if ($requirement->getResult() == RequirementResult::Failed) { $installResult = InstallStatus::Failure; break; } else { if ($requirement->getResult() == RequirementResult::Warning) { $installResult = InstallStatus::Warning; } } } $writableFolders = $this->_getWritableFolders(); $errorFolders = null; foreach ($writableFolders as $writableFolder) { if (!IOHelper::isWritable($writableFolder)) { $errorFolders[] = IOHelper::getRealPath($writableFolder); $installResult = InstallStatus::Failure; } } $this->_result = $installResult; $this->_serverInfo = $this->_calculateServerInfo(); $this->_errorFolders = $errorFolders; }