/** * @param bool $suppressErrors * @return bool */ public function clear($suppressErrors = false) { if (!IOHelper::clearFolder($this->getRealPath(), $suppressErrors)) { return false; } return true; }
/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { Craft::log('Clearing asset caches', LogLevel::Info, true); $path = craft()->path->getRuntimePath() . 'assets'; IOHelper::clearFolder($path); Craft::log('Done clearing asset caches', LogLevel::Info, true); return true; }
/** * Performs the tool's action. * * @param array $params * @return array */ public function performAction($params = array()) { if (!isset($params['folders'])) { return; } $allFolders = array_keys($this->_getFolders()); if ($params['folders'] == '*') { $folders = $allFolders; } else { $folders = $params['folders']; } foreach ($folders as $folder) { if (in_array($folder, $allFolders)) { $path = craft()->path->getRuntimePath() . $folder; IOHelper::clearFolder($path, true); } } }
/** * @param $srcZip * @param $destFolder * * @return bool */ public static function unzip($srcZip, $destFolder) { craft()->config->maxPowerCaptain(); if (IOHelper::fileExists($srcZip)) { if (IOHelper::getExtension($srcZip) == 'zip') { if (!IOHelper::folderExists($destFolder)) { if (!IOHelper::createFolder($destFolder)) { Craft::log('Tried to create the unzip destination folder, but could not: ' . $destFolder, LogLevel::Error); return false; } } else { // If the destination folder exists and it has contents, clear them. if (($conents = IOHelper::getFolderContents($destFolder)) !== false) { // Begin the great purge. if (!IOHelper::clearFolder($destFolder)) { Craft::log('Tried to clear the contents of the unzip destination folder, but could not: ' . $destFolder, LogLevel::Error); return false; } } } $zip = static::_getZipInstance($srcZip); $result = $zip->unzip($srcZip, $destFolder); if ($result === true) { return $result; } else { Craft::log('There was an error unzipping the file: ' . $srcZip, LogLevel::Error); return false; } } else { Craft::log($srcZip . ' is not a zip file and cannot be unzipped.', LogLevel::Error); return false; } } else { Craft::log('Unzipping is only available for files.', LogLevel::Error); return false; } }
/** * @param $manifestData * @param $sourceTempFolder * @param $handle * * @return bool */ public static function doFileUpdate($manifestData, $sourceTempFolder, $handle) { if ($handle == 'craft') { $destDirectory = craft()->path->getAppPath(); $sourceFileDirectory = 'app/'; } else { $destDirectory = craft()->path->getPluginsPath() . $handle . '/'; $sourceFileDirectory = ''; } 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($destDirectory . $tempPath); $sourceFile = IOHelper::getRealPath(IOHelper::normalizePathSeparators($sourceTempFolder . '/' . $sourceFileDirectory . $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, $handle); return false; } return true; }
/** * Delete logo. * * @return null */ public function actionDeleteSiteImage() { $this->requireAdmin(); $type = craft()->request->getRequiredPost('type'); if (!in_array($type, $this->_allowedTypes)) { $this->returnErrorJson(Craft::t('That is not a legal site image type.')); } IOHelper::clearFolder(craft()->path->getRebrandPath() . $type . '/'); $html = craft()->templates->render('settings/general/_images/' . $type); $this->returnJson(array('html' => $html)); }
/** * @return bool */ public function flushUpdateInfoFromCache() { Craft::log('Flushing update info from cache.', LogLevel::Info, true); if (IOHelper::clearFolder(craft()->path->getCompiledTemplatesPath(), true) && IOHelper::clearFolder(craft()->path->getCachePath(), true)) { return true; } return false; }
/** * Crop user photo. * * @return null */ public function actionCropUserPhoto() { $this->requireAjaxRequest(); craft()->userSession->requireLogin(); $userId = craft()->request->getRequiredPost('userId'); if ($userId != craft()->userSession->getUser()->id) { craft()->userSession->requirePermission('editUsers'); } try { $x1 = craft()->request->getRequiredPost('x1'); $x2 = craft()->request->getRequiredPost('x2'); $y1 = craft()->request->getRequiredPost('y1'); $y2 = craft()->request->getRequiredPost('y2'); $source = craft()->request->getRequiredPost('source'); // Strip off any querystring info, if any. $source = UrlHelper::stripQueryString($source); $user = craft()->users->getUserById($userId); $userName = AssetsHelper::cleanAssetName($user->username, false); // make sure that this is this user's file $imagePath = craft()->path->getTempUploadsPath() . 'userphotos/' . $userName . '/' . $source; if (IOHelper::fileExists($imagePath) && craft()->images->checkMemoryForImage($imagePath)) { craft()->users->deleteUserPhoto($user); $image = craft()->images->loadImage($imagePath); $image->crop($x1, $x2, $y1, $y2); if (craft()->users->saveUserPhoto(IOHelper::getFileName($imagePath), $image, $user)) { IOHelper::clearFolder(craft()->path->getTempUploadsPath() . 'userphotos/' . $userName); $html = craft()->templates->render('users/_userphoto', array('account' => $user)); $this->returnJson(array('html' => $html)); } } IOHelper::clearFolder(craft()->path->getTempUploadsPath() . 'userphotos/' . $userName); } catch (Exception $exception) { $this->returnErrorJson($exception->getMessage()); } $this->returnErrorJson(Craft::t('Something went wrong when processing the photo.')); }
/** * @throws HttpException * @return null */ private function _processUpdateLogic() { // Let all non-action CP requests through. if ($this->request->isCpRequest() && (!$this->request->isActionRequest() || $this->request->getActionSegments() == array('users', 'login'))) { // If this is a request to actually manually update Craft, do it if ($this->request->getSegment(1) == 'manualupdate') { $this->runController('templates/manualUpdate'); $this->end(); } else { if ($this->updates->isBreakpointUpdateNeeded()) { throw new HttpException(200, Craft::t('You need to be on at least Craft CMS {url} before you can manually update to Craft CMS {targetVersion} build {targetBuild}.', array('url' => '[build ' . CRAFT_MIN_BUILD_REQUIRED . '](' . CRAFT_MIN_BUILD_URL . ')', 'targetVersion' => CRAFT_VERSION, 'targetBuild' => CRAFT_BUILD))); } else { if (!$this->request->isAjaxRequest()) { if ($this->request->getPathInfo() !== '') { $this->userSession->setReturnUrl($this->request->getPath()); } } // Clear the template caches in case they've been compiled since this release was cut. IOHelper::clearFolder($this->path->getCompiledTemplatesPath()); // Show the manual update notification template $this->runController('templates/manualUpdateNotification'); } } } else { if ($this->request->isActionRequest() && ($actionSegs = $this->request->getActionSegments()) !== null && isset($actionSegs[0]) && $actionSegs[0] == 'update') { $controller = $actionSegs[0]; $action = isset($actionSegs[1]) ? $actionSegs[1] : 'index'; $this->runController($controller . '/' . $action); } else { // If an exception gets throw during the rendering of the 503 template, let // TemplatesController->actionRenderError() take care of it. throw new HttpException(503); } } // <Gandalf> YOU SHALL NOT PASS! $this->end(); }
/** * Performs the tool's action. * * @param array $params * * @return null */ public function performAction($params = array()) { if (!isset($params['caches'])) { return; } $allFolderKeys = array_keys($this->_getFolders()); if ($params['caches'] == '*') { $folders = $allFolderKeys; } else { $folders = array(); foreach ($params['caches'] as $cacheKey) { if (in_array($cacheKey, $allFolderKeys)) { $folders[] = $cacheKey; } } } $allFolders = array_keys($this->_getFolders(false)); foreach ($folders as $folder) { foreach ($allFolders as $allFolder) { if (md5($allFolder) == $folder) { if ($allFolder == 'dataCache') { craft()->cache->flush(); } else { IOHelper::clearFolder($allFolder, true); break; } } } } if ($params['caches'] == '*' || in_array('templateCaches', $params['caches'])) { craft()->templateCache->deleteAllCaches(); } if ($params['caches'] == '*' || in_array('assetTransformIndex', $params['caches'])) { craft()->db->createCommand()->truncateTable('assettransformindex'); } if ($params['caches'] == '*' || in_array('assetIndexingData', $params['caches'])) { craft()->db->createCommand()->truncateTable('assetindexdata'); } }
/** * Delete logo. */ public function actionDeleteLogo() { $this->requireAdmin(); IOHelper::clearFolder(craft()->path->getStoragePath() . 'logo/'); $html = craft()->templates->render('settings/general/_logo'); $this->returnJson(array('html' => $html)); }
/** * Remove any temp files and/or folders that might have been created. */ private function _cleanTempFiles($unzipFolder) { // Get rid of all the .bak files/folders. $baks = IOHelper::getFolderContents(craft()->path->getAppPath(), true, ".*\\.bak\$"); foreach ($baks as $bak) { if (IOHelper::fileExists($bak)) { if (IOHelper::isWritable($bak)) { Craft::log('Deleting .bak file: ' . $bak, LogLevel::Info, true); IOHelper::deleteFile($bak, true); } } else { if (IOHelper::folderExists($bak)) { if (IOHelper::isWritable($bak)) { Craft::log('Deleting .bak folder:' . $bak, LogLevel::Info, true); IOHelper::clearFolder($bak, true); IOHelper::deleteFolder($bak, true); } } } } // Now delete any files/folders that were marked for deletion in the manifest file. $manifestData = UpdateHelper::getManifestData($unzipFolder); if ($manifestData) { foreach ($manifestData as $row) { if (UpdateHelper::isManifestVersionInfoLine($row)) { continue; } $rowData = explode(';', $row); $folder = false; if (UpdateHelper::isManifestLineAFolder($rowData[0])) { $folder = true; $tempFilePath = UpdateHelper::cleanManifestFolderLine($rowData[0]); } else { $tempFilePath = $rowData[0]; } $fullPath = ''; switch (trim($rowData[1])) { // If the file/folder was set to be deleted, there is no backup and we go ahead and remove it now. case PatchManifestFileAction::Remove: if ($tempFilePath == '') { $fullPath = IOHelper::normalizePathSeparators(craft()->path->getAppPath()); } else { $fullPath = IOHelper::normalizePathSeparators(craft()->path->getAppPath() . $tempFilePath); } break; } // Delete any files/folders we backed up. if ($folder) { if (($folder = IOHelper::getFolder($fullPath)) !== false) { Craft::log('Deleting folder: ' . $folder->getRealPath(), LogLevel::Info, true); $folder->delete(); } } else { if (($file = IOHelper::getFile($fullPath)) !== false) { Craft::log('Deleting file: ' . $file->getRealPath(), LogLevel::Info, true); $file->delete(); } } } } // Clear the temp folder. IOHelper::clearFolder(craft()->path->getTempPath(), true); }
public function actionSendSupportRequest() { $this->requirePostRequest(); craft()->config->maxPowerCaptain(); $success = false; $errors = array(); $zipFile = null; $tempFolder = null; $getHelpModel = new FeedMe_GetHelpModel(); $getHelpModel->fromEmail = craft()->request->getPost('fromEmail'); $getHelpModel->feedIssue = craft()->request->getPost('feedIssue'); $getHelpModel->message = trim(craft()->request->getPost('message')); $getHelpModel->attachLogs = (bool) craft()->request->getPost('attachLogs'); $getHelpModel->attachSettings = (bool) craft()->request->getPost('attachSettings'); $getHelpModel->attachFeed = (bool) craft()->request->getPost('attachFeed'); $getHelpModel->attachFields = (bool) craft()->request->getPost('attachFields'); $getHelpModel->attachment = UploadedFile::getInstanceByName('attachAdditionalFile'); if ($getHelpModel->validate()) { $plugin = craft()->plugins->getPlugin('feedMe'); $feed = craft()->feedMe_feeds->getFeedById($getHelpModel->feedIssue); // Add some extra info about this install $message = $getHelpModel->message . "\n\n" . "------------------------------\n\n" . 'Craft ' . craft()->getEditionName() . ' ' . craft()->getVersion() . '.' . craft()->getBuild() . "\n\n" . 'Feed Me ' . $plugin->getVersion(); try { $zipFile = $this->_createZip(); $tempFolder = craft()->path->getTempPath() . StringHelper::UUID() . '/'; if (!IOHelper::folderExists($tempFolder)) { IOHelper::createFolder($tempFolder); } // // Attached just the Feed Me log // if ($getHelpModel->attachLogs) { if (IOHelper::folderExists(craft()->path->getLogPath())) { $logFolderContents = IOHelper::getFolderContents(craft()->path->getLogPath()); foreach ($logFolderContents as $file) { // Just grab the Feed Me log if (IOHelper::fileExists($file) && basename($file) == 'feedme.log') { Zip::add($zipFile, $file, craft()->path->getStoragePath()); } } } } // // Backup our feed settings // if ($getHelpModel->attachSettings) { if (IOHelper::folderExists(craft()->path->getDbBackupPath())) { $backup = craft()->path->getDbBackupPath() . StringHelper::toLowerCase('feedme_' . gmdate('ymd_His') . '.sql'); $feedInfo = $this->_prepareSqlFeedSettings($getHelpModel->feedIssue); IOHelper::writeToFile($backup, $feedInfo . PHP_EOL, true, true); Zip::add($zipFile, $backup, craft()->path->getStoragePath()); } } // // Save the contents of the feed // if ($getHelpModel->attachFeed) { $feedData = craft()->feedMe_feed->getRawData($feed->feedUrl); $tempFile = $tempFolder . 'feed.' . StringHelper::toLowerCase($feed->feedType); IOHelper::writeToFile($tempFile, $feedData . PHP_EOL, true, true); if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } // // Get some information about the fields we're mapping to - handy to know // if ($getHelpModel->attachFields) { $fieldInfo = array(); foreach ($feed->fieldMapping as $feedHandle => $fieldHandle) { $field = craft()->fields->getFieldByHandle($fieldHandle); if ($field) { $fieldInfo[] = $this->_prepareExportField($field); } } // Support PHP <5.4, JSON_PRETTY_PRINT = 128, JSON_NUMERIC_CHECK = 32 $json = json_encode($fieldInfo, 128 | 32); $tempFile = $tempFolder . 'fields.json'; IOHelper::writeToFile($tempFile, $json . PHP_EOL, true, true); if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } // // Add in any additional attachments // if ($getHelpModel->attachment) { $tempFile = $tempFolder . $getHelpModel->attachment->getName(); $getHelpModel->attachment->saveAs($tempFile); // Make sure it actually saved. if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } } catch (\Exception $e) { FeedMePlugin::log('Tried to attach debug logs to a support request and something went horribly wrong: ' . $e->getMessage(), LogLevel::Warning, true); } $email = new EmailModel(); $email->fromEmail = $getHelpModel->fromEmail; $email->toEmail = "*****@*****.**"; $email->subject = "Feed Me Support"; $email->body = $message; if ($zipFile) { $email->addAttachment($zipFile, 'FeedMeSupportAttachment.zip', 'base64', 'application/zip'); } $result = craft()->email->sendEmail($email); if ($result) { if ($zipFile) { if (IOHelper::fileExists($zipFile)) { IOHelper::deleteFile($zipFile); } } if ($tempFolder) { IOHelper::clearFolder($tempFolder); IOHelper::deleteFolder($tempFolder); } $success = true; } else { $errors = array('Support' => array('Unable to contact support. Please try again soon.')); } } else { $errors = $getHelpModel->getErrors(); } $this->returnJson(array('success' => $success, 'errors' => $errors)); }
/** * Any migration code in here is wrapped inside of a transaction. * * @return bool */ public function safeUp() { IOHelper::clearFolder(craft()->path->getCompiledTemplatesPath(), true); return true; }
/** * Remove any temp files and/or folders that might have been created. * * @param string $unzipFolder * * @return null */ private function _cleanTempFiles($unzipFolder) { $appPath = craft()->path->getAppPath(); // Get rid of all the .bak files/folders. $filesToDelete = IOHelper::getFolderContents($appPath, true, ".*\\.bak\$"); // Now delete any files/folders that were marked for deletion in the manifest file. $manifestData = UpdateHelper::getManifestData($unzipFolder); if ($manifestData) { foreach ($manifestData as $row) { if (UpdateHelper::isManifestVersionInfoLine($row)) { continue; } $rowData = explode(';', $row); if ($rowData[1] == PatchManifestFileAction::Remove) { if (UpdateHelper::isManifestLineAFolder($rowData[0])) { $tempFilePath = UpdateHelper::cleanManifestFolderLine($rowData[0]); } else { $tempFilePath = $rowData[0]; } $filesToDelete[] = $appPath . $tempFilePath; } } foreach ($filesToDelete as $fileToDelete) { if (IOHelper::fileExists($fileToDelete)) { if (IOHelper::isWritable($fileToDelete)) { Craft::log('Deleting file: ' . $fileToDelete, LogLevel::Info, true); IOHelper::deleteFile($fileToDelete, true); } } else { if (IOHelper::folderExists($fileToDelete)) { if (IOHelper::isWritable($fileToDelete)) { Craft::log('Deleting .bak folder:' . $fileToDelete, LogLevel::Info, true); IOHelper::clearFolder($fileToDelete, true); IOHelper::deleteFolder($fileToDelete, true); } } } } } // Clear the temp folder. IOHelper::clearFolder(craft()->path->getTempPath(), true); }
/** * Remove any temp files and/or folders that might have been created. * * @param string $unzipFolder * @param string $handle * * @return null */ private function _cleanTempFiles($unzipFolder, $handle) { $path = $handle == 'craft' ? craft()->path->getAppPath() : craft()->path->getPluginsPath() . $handle . '/'; // Get rid of all the .bak files/folders. $filesToDelete = IOHelper::getFolderContents($path, true, ".*\\.bak\$"); // Now delete any files/folders that were marked for deletion in the manifest file. $manifestData = UpdateHelper::getManifestData($unzipFolder, $handle); if ($manifestData) { foreach ($manifestData as $row) { if (UpdateHelper::isManifestVersionInfoLine($row)) { continue; } $rowData = explode(';', $row); if ($rowData[1] == PatchManifestFileAction::Remove) { if (UpdateHelper::isManifestLineAFolder($rowData[0])) { $tempFilePath = UpdateHelper::cleanManifestFolderLine($rowData[0]); } else { $tempFilePath = $rowData[0]; } $filesToDelete[] = $path . $tempFilePath; } // In case we did the whole app folder if ($rowData[0][0] == '*') { $filesToDelete[] = rtrim(IOHelper::normalizePathSeparators($path), '/') . '.bak/'; } } foreach ($filesToDelete as $fileToDelete) { if (IOHelper::fileExists($fileToDelete)) { if (IOHelper::isWritable($fileToDelete)) { Craft::log('Deleting file: ' . $fileToDelete, LogLevel::Info, true); IOHelper::deleteFile($fileToDelete, true); // If that was the last file in this folder, nuke the folder. if (IOHelper::isFolderEmpty(IOHelper::getFolderName($fileToDelete))) { IOHelper::deleteFolder(IOHelper::getFolderName($fileToDelete)); } } } else { if (IOHelper::folderExists($fileToDelete)) { if (IOHelper::isWritable($fileToDelete)) { Craft::log('Deleting .bak folder:' . $fileToDelete, LogLevel::Info, true); IOHelper::clearFolder($fileToDelete, true); IOHelper::deleteFolder($fileToDelete, true); } } } } } // Clear the temp folder. IOHelper::clearFolder(craft()->path->getTempPath(), true); }
/** * Creates a new support ticket for the GetHelp widget. * * @return null */ public function actionSendSupportRequest() { $this->requirePostRequest(); craft()->config->maxPowerCaptain(); $success = false; $errors = array(); $zipFile = null; $tempFolder = null; $widgetId = craft()->request->getPost('widgetId'); $namespace = craft()->request->getPost('namespace'); $namespace = $namespace ? $namespace . '.' : ''; $getHelpModel = new GetHelpModel(); $getHelpModel->fromEmail = craft()->request->getPost($namespace . 'fromEmail'); $getHelpModel->message = trim(craft()->request->getPost($namespace . 'message')); $getHelpModel->attachLogs = (bool) craft()->request->getPost($namespace . 'attachLogs'); $getHelpModel->attachDbBackup = (bool) craft()->request->getPost($namespace . 'attachDbBackup'); $getHelpModel->attachTemplates = (bool) craft()->request->getPost($namespace . 'attachTemplates'); $getHelpModel->attachment = UploadedFile::getInstanceByName($namespace . 'attachAdditionalFile'); if ($getHelpModel->validate()) { $user = craft()->userSession->getUser(); // Add some extra info about this install $message = $getHelpModel->message . "\n\n" . "------------------------------\n\n" . 'Craft ' . craft()->getEditionName() . ' ' . craft()->getVersion() . '.' . craft()->getBuild(); $plugins = craft()->plugins->getPlugins(); if ($plugins) { $pluginNames = array(); foreach ($plugins as $plugin) { $pluginNames[] = $plugin->getName() . ' ' . $plugin->getVersion() . ' (' . $plugin->getDeveloper() . ')'; } $message .= "\nPlugins: " . implode(', ', $pluginNames); } $requestParamDefaults = array('sFirstName' => $user->getFriendlyName(), 'sLastName' => $user->lastName ? $user->lastName : 'Doe', 'sEmail' => $getHelpModel->fromEmail, 'tNote' => $message); $requestParams = $requestParamDefaults; $hsParams = array('helpSpotApiURL' => 'https://support.pixelandtonic.com/api/index.php'); try { if ($getHelpModel->attachLogs || $getHelpModel->attachDbBackup) { if (!$zipFile) { $zipFile = $this->_createZip(); } if ($getHelpModel->attachLogs && IOHelper::folderExists(craft()->path->getLogPath())) { // Grab it all. $logFolderContents = IOHelper::getFolderContents(craft()->path->getLogPath()); foreach ($logFolderContents as $file) { // Make sure it's a file. if (IOHelper::fileExists($file)) { Zip::add($zipFile, $file, craft()->path->getStoragePath()); } } } if ($getHelpModel->attachDbBackup && IOHelper::folderExists(craft()->path->getDbBackupPath())) { // Make a fresh database backup of the current schema/data. We want all data from all tables // for debugging. craft()->db->backup(); $backups = IOHelper::getLastModifiedFiles(craft()->path->getDbBackupPath(), 3); foreach ($backups as $backup) { if (IOHelper::getExtension($backup) == 'sql') { Zip::add($zipFile, $backup, craft()->path->getStoragePath()); } } } } if ($getHelpModel->attachment) { // If we don't have a zip file yet, create one now. if (!$zipFile) { $zipFile = $this->_createZip(); } $tempFolder = craft()->path->getTempPath() . StringHelper::UUID() . '/'; if (!IOHelper::folderExists($tempFolder)) { IOHelper::createFolder($tempFolder); } $tempFile = $tempFolder . $getHelpModel->attachment->getName(); $getHelpModel->attachment->saveAs($tempFile); // Make sure it actually saved. if (IOHelper::fileExists($tempFile)) { Zip::add($zipFile, $tempFile, $tempFolder); } } if ($getHelpModel->attachTemplates) { // If we don't have a zip file yet, create one now. if (!$zipFile) { $zipFile = $this->_createZip(); } if (IOHelper::folderExists(craft()->path->getLogPath())) { // Grab it all. $templateFolderContents = IOHelper::getFolderContents(craft()->path->getSiteTemplatesPath()); foreach ($templateFolderContents as $file) { // Make sure it's a file. if (IOHelper::fileExists($file)) { $templateFolderName = IOHelper::getFolderName(craft()->path->getSiteTemplatesPath(), false); $siteTemplatePath = craft()->path->getSiteTemplatesPath(); $tempPath = substr($siteTemplatePath, 0, strlen($siteTemplatePath) - strlen($templateFolderName) - 1); Zip::add($zipFile, $file, $tempPath); } } } } if ($zipFile) { $requestParams['File1_sFilename'] = 'SupportAttachment-' . IOHelper::cleanFilename(craft()->getSiteName()) . '.zip'; $requestParams['File1_sFileMimeType'] = 'application/zip'; $requestParams['File1_bFileBody'] = base64_encode(IOHelper::getFileContents($zipFile)); // Bump the default timeout because of the attachment. $hsParams['callTimeout'] = 120; } // Grab the license.key file. if (IOHelper::fileExists(craft()->path->getLicenseKeyPath())) { $requestParams['File2_sFilename'] = 'license.key'; $requestParams['File2_sFileMimeType'] = 'text/plain'; $requestParams['File2_bFileBody'] = base64_encode(IOHelper::getFileContents(craft()->path->getLicenseKeyPath())); } } catch (\Exception $e) { Craft::log('Tried to attach debug logs to a support request and something went horribly wrong: ' . $e->getMessage(), LogLevel::Warning); // There was a problem zipping, so reset the params and just send the email without the attachment. $requestParams = $requestParamDefaults; } require_once craft()->path->getLibPath() . 'HelpSpotAPI.php'; $hsapi = new \HelpSpotAPI($hsParams); $result = $hsapi->requestCreate($requestParams); if ($result) { if ($zipFile) { if (IOHelper::fileExists($zipFile)) { IOHelper::deleteFile($zipFile); } } if ($tempFolder) { IOHelper::clearFolder($tempFolder); IOHelper::deleteFolder($tempFolder); } $success = true; } else { $hsErrors = array_filter(preg_split("/(\r\n|\n|\r)/", $hsapi->errors)); $errors = array('Support' => $hsErrors); } } else { $errors = $getHelpModel->getErrors(); } $this->renderTemplate('_components/widgets/GetHelp/response', array('success' => $success, 'errors' => JsonHelper::encode($errors), 'widgetId' => $widgetId)); }