private function migrateBackupFileNames() { $tasks = (array) $this->context->optionGet('mwp_backup_tasks'); $changed = false; foreach ($tasks as $taskName => $taskInfo) { if (!isset($taskInfo['task_results']) || !is_array($taskInfo['task_results'])) { continue; } foreach ($taskInfo['task_results'] as $resultId => $taskResult) { if (!isset($taskResult['server']['file_path']) || !file_exists($taskResult['server']['file_path'])) { continue; } $filePath = $taskResult['server']['file_path']; $hash = $this->generateRandomHash(filesize($filePath)); $newFilePath = preg_replace('{_[a-z0-9]{32}\\.zip$}', sprintf('_%s.zip', $hash), $filePath); $renamed = rename($filePath, $newFilePath); if (!$renamed) { continue; } $changed = true; $oldUrl = $tasks[$taskName]['task_results'][$resultId]['server']['file_url']; $newUrl = preg_replace('{_[a-z0-9]{32}\\.zip$}', sprintf('_%s.zip', $hash), $oldUrl); $tasks[$taskName]['task_results'][$resultId]['server']['file_path'] = $newFilePath; $tasks[$taskName]['task_results'][$resultId]['server']['file_url'] = $newUrl; } } if (!$changed) { return; } $this->context->optionSet('mwp_backup_tasks', $tasks); }
public function __construct(MWP_WordPress_Context $context) { $this->context = $context; $brand = $context->optionGet(self::OPTION_NAME); if (!is_array($brand)) { return; } $this->name = empty($brand['name']) ? null : $brand['name']; $this->description = empty($brand['desc']) ? null : $brand['desc']; $this->author = empty($brand['author']) ? null : $brand['author']; $this->authorUrl = empty($brand['author_url']) ? null : $brand['author_url']; $this->hide = isset($brand['hide']) ? $brand['hide'] : $this->hide; // "Dissalow" [sic] edit . $this->disallowEdit = isset($brand['dissalow_edit']) ? $brand['dissalow_edit'] : $this->disallowEdit; $this->textForClient = empty($brand['text_for_client']) ? null : $brand['text_for_client']; $this->contactType = isset($brand['email_or_link']) ? (int) $brand['email_or_link'] : self::CONTACT_TYPE_NONE; $this->adminEmail = empty($brand['admin_email']) ? null : $brand['admin_email']; $this->active = isset($brand['active']) ? $brand['active'] : (bool) ($this->name || $this->description || $this->author || $this->authorUrl || $this->hide || $this->disallowEdit || $this->contactType); }
public static function createFromWordPressContext(MWP_WordPress_Context $context) { return self::createFromArray(array('username' => $context->getConstant('DB_USER'), 'password' => $context->getConstant('DB_PASSWORD'), 'database' => $context->getConstant('DB_NAME'), 'host' => $context->getConstant('DB_HOST'), 'charset' => $context->hasConstant('DB_CHARSET') ? $context->getConstant('DB_CHARSET') : 'utf8')); }