/** * Initialises the steps array */ public function initialiseSteps() { $this->steps = $this->defaultSteps; $data = $this->input->getData(); $this->steps['database'] = AModel::getAnInstance('Database', 'AngieModel')->getDatabaseNames(); // Do I have off-site directories? $offsitedirs = AModel::getAnInstance('Offsitedirs', 'AngieModel')->getDirs(); if ($offsitedirs) { // Rearrange steps order to inject off-site dirs restore after the db step $savedSteps = $this->steps; $this->steps = array(); $this->steps['main'] = $savedSteps['main']; $this->steps['database'] = $savedSteps['database']; $this->steps['offsitedirs'] = $offsitedirs; $this->steps['setup'] = $savedSteps['setup']; $this->steps['finalise'] = $savedSteps['finalise']; } // Do I have a site setup step? $fileNameMain = APATH_INSTALLATION . '/angie/controllers/setup.php'; $fileNameAlt = APATH_INSTALLATION . '/angie/platform/controllers/setup.php'; if (!@file_exists($fileNameAlt) && !@file_exists($fileNameMain)) { unset($this->steps['setup']); } $this->input->setData($data); }
public function readAliases() { $sites = APATH_SITE . '/sites/sites.php'; if (!file_exists($sites)) { return array(); } $contents = file_get_contents($sites); $tokenizer = new AUtilsPhptokenizer($contents); $skip = 0; $error = false; $tokens = array(); // Database info while (!$error) { try { // Let's try to extract all the occurrences until we get an error. Since it's just a PHP array, // you could write it in a million of different ways $info = $tokenizer->searchToken('T_VARIABLE', '$sites', $skip); $skip = $info['endLine'] + 1; $tokens[] = $info['data']; } catch (RuntimeException $e) { $error = true; } } if (!$tokens) { return array(); } // Let's use Configuration model function to extract the data we need /** @var AngieModelDrupal8Configuration $configModel */ $configModel = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container); $aliases = $configModel->extractVariables($tokens, 'sites'); return $aliases; }
public function onBeforeMain() { ADocument::getInstance()->addScriptDeclaration(<<<ENDSRIPT var akeebaAjax = null; \$(document).ready(function(){ akeebaAjax = new akeebaAjaxConnector('index.php'); akeebaAjax.callJSON({ 'view' : 'runscripts', 'format' : 'raw' }); }); ENDSRIPT ); $model = $this->getModel(); $this->showconfig = $model->getState('showconfig', 0); if ($this->showconfig) { $this->configuration = AModel::getAnInstance('Configuration', 'AngieModel')->getFileContents(); } if (ASession::getInstance()->get('tfa_warning', false)) { $this->extra_warning = '<div class="alert alert-block alert-error">'; $this->extra_warning .= '<h4 class="alert-heading">' . AText::_('FINALISE_TFA_DISABLED_TITLE') . '</h4>'; $this->extra_warning .= '<p>' . AText::_('FINALISE_TFA_DISABLED_BODY') . '</p>'; $this->extra_warning .= '</div>'; } return true; }
/** * Returns the database connection variables for the default database. * * @return null|stdClass */ protected function getDbConnectionVars() { /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); return $model->getDatabaseInfo($firstDbKey); }
public function onBeforeMain() { $stepsModel = AModel::getAnInstance('Steps', 'AngieModel'); $dbModel = AModel::getAnInstance('Database', 'AngieModel'); $this->substep = $stepsModel->getActiveSubstep(); $this->number_of_substeps = $stepsModel->getNumberOfSubsteps(); $this->db = $dbModel->getDatabaseInfo($this->substep); return true; }
public function onBeforeMain() { $model = $this->getModel(); $this->showconfig = $model->getState('showconfig', 0); if ($this->showconfig) { $this->configuration = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container)->getFileContents(); } return true; }
/** * Initialises the steps array */ public function initialiseSteps() { $this->steps = $this->defaultSteps; $data = $this->input->getData(); /** @var AngieModelDatabase $dbModel */ $dbModel = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $this->steps['database'] = $dbModel->getDatabaseNames(); // Do I have off-site directories? /** @var AngieModelBaseOffsitedirs $offsiteModel */ $offsiteModel = AModel::getAnInstance('Offsitedirs', 'AngieModel', array(), $this->container); $offsitedirs = $offsiteModel->getDirs(); if ($offsitedirs) { // Rearrange steps order to inject off-site dirs restore after the db step $savedSteps = $this->steps; $this->steps = array(); $this->steps['main'] = $savedSteps['main']; $this->steps['database'] = $savedSteps['database']; $this->steps['offsitedirs'] = $offsitedirs; $this->steps['setup'] = $savedSteps['setup']; $this->steps['finalise'] = $savedSteps['finalise']; } // Do I have a site setup step? $fileNameMain = APATH_INSTALLATION . '/angie/controllers/setup.php'; $fileNameAlt = ''; $altFiles = array(APATH_INSTALLATION . '/angie/platform/controllers/setup.php', APATH_INSTALLATION . '/platform/controllers/setup.php', APATH_INSTALLATION . '/platform/controllers/' . strtolower(ANGIE_INSTALLER_NAME) . 'setup.php'); foreach ($altFiles as $altFile) { if (file_exists($altFile)) { $fileNameAlt = $altFile; break; } } if (!@file_exists($fileNameAlt)) { $fileNameAlt = APATH_INSTALLATION . '/platform/controllers/setup.php'; } if (!@file_exists($fileNameAlt) && !@file_exists($fileNameMain)) { unset($this->steps['setup']); } $fileNameMain = APATH_INSTALLATION . '/angie/platform/steps.php'; $fileNameAlt = APATH_INSTALLATION . '/platform/steps.php'; if (@file_exists($fileNameMain)) { @(include_once $fileNameMain); } elseif (@file_exists($fileNameAlt)) { @(include_once $fileNameAlt); } if (class_exists('PlatformSteps')) { $platformSteps = new PlatformSteps(); if (method_exists($platformSteps, 'additionalSteps')) { $steps = $platformSteps->additionalSteps($this->steps); if (is_array($steps) && !empty($steps)) { $this->steps = $steps; } } } // @todo Load additional steps $this->input->setData($data); }
public function onBeforeMain() { $stepsModel = AModel::getAnInstance('Steps', 'AngieModel'); $offsiteModel = AModel::getAnInstance('Offsitedirs', 'AngieModel'); $substeps = $offsiteModel->getDirs(true, true); $cursubstep = $stepsModel->getActiveSubstep(); $this->substep = $substeps[$cursubstep]; $this->number_of_substeps = $stepsModel->getNumberOfSubsteps(); return true; }
public function onBeforeMain() { /** @var AngieModelSteps $stepsModel */ $stepsModel = AModel::getAnInstance('Steps', 'AngieModel', array(), $this->container); /** @var AngieModelDatabase $dbModel */ $dbModel = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $this->substep = $stepsModel->getActiveSubstep(); $this->number_of_substeps = $stepsModel->getNumberOfSubsteps(); $this->db = $dbModel->getDatabaseInfo($this->substep); return true; }
public function onBeforeMain() { /** @var AngieModelSteps $stepsModel */ $stepsModel = AModel::getAnInstance('Steps', 'AngieModel', array(), $this->container); /** @var AngieModelOffsitedirs $offsiteModel */ $offsiteModel = AModel::getAnInstance('Offsitedirs', 'AngieModel', array(), $this->container); $substeps = $offsiteModel->getDirs(true, true); $cursubstep = $stepsModel->getActiveSubstep(); $this->substep = $substeps[$cursubstep]; $this->number_of_substeps = $stepsModel->getNumberOfSubsteps(); return true; }
public function step() { $key = $this->input->get('key', null); $model = AModel::getAnInstance('Database', 'AngieModel'); $data = $model->getDatabaseInfo($key); try { $restoreEngine = ADatabaseRestore::getInstance($key, $data); $result = $restoreEngine->stepRestoration(); } catch (Exception $exc) { $result = array('percent' => 0, 'restored' => 0, 'total' => 0, 'eta' => 0, 'error' => $exc->getMessage(), 'done' => 1); } echo json_encode($result); }
/** * Is this a multisite installation? */ public function ismultisite() { /** @var AngieModelDrupal7Configuration $configModel */ $configModel = AModel::getAnInstance('Configuration', 'AngieModel'); $folders = $configModel->getSettingsFolders(); // If I have more than a folder containing the settings.php file it means that this is // a multisite installation if (count($folders) > 1) { echo json_encode(true); } else { echo json_encode(false); } }
public function replaceneeded() { /** @var AngieModelWordpressConfiguration $config */ $config = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container); $result = true; // These values are stored inside the session, after the setup step $old_url = $config->get('oldurl'); $new_url = $config->get('homeurl'); // If we are restoring to the same URL we don't need to replace any data if ($old_url == $new_url) { $result = false; } echo json_encode($result); }
public function main() { /** @var AngieModelMauticConfiguration $config */ $config = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container); // These values are stored inside the session, after the setup step $old_url = $config->get('old_live_site'); $new_url = $config->get('live_site'); // If we are restoring to the same URL we don't need to replace any data if ($old_url == $new_url) { $this->setRedirect('index.php?view=finalise'); return; } parent::main(); }
/** * Adds additional steps for this installer * * @param array $steps * * @return mixed */ public function additionalSteps(array $steps) { /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array()); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); $connectionVars = $model->getDatabaseInfo($firstDbKey); // If I have a sqlite database I have to skip database restoration. It's just a simple file to drop if ($connectionVars->dbtype == 'sqlite') { if (isset($steps['database'])) { unset($steps['database']); } } return $steps; }
/** * Try to read the configuration */ public function getconfig() { // Load the default configuration and save it to the session $data = $this->input->getData(); /** @var AngieModelMagento2Configuration $model */ $model = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container); $this->input->setData($data); $this->container->session->saveData(); $vars = $model->loadFromFile(); foreach ($vars as $k => $v) { $model->set($k, $v); } $this->container->session->saveData(); echo json_encode(true); }
public function onBeforeMain() { $this->container->application->getDocument()->addScriptDeclaration(<<<ENDSRIPT var akeebaAjax = null; \$(document).ready(function(){ akeebaAjax = new akeebaAjaxConnector('index.php'); }); ENDSRIPT ); $model = $this->getModel(); $this->showconfig = $model->getState('showconfig', 0); if ($this->showconfig) { $this->configuration = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container)->getFileContents(); } return true; }
/** * Initialises the steps array */ public function initialiseSteps() { $this->steps = $this->defaultSteps; $data = $this->input->getData(); $this->steps['database'] = AModel::getAnInstance('Database', 'AngieModel')->getDatabaseNames(); // Do I have off-site directories? $offsitedirs = AModel::getAnInstance('Offsitedirs', 'AngieModel')->getDirs(); if ($offsitedirs) { // Rearrange steps order to inject off-site dirs restore after the db step $savedSteps = $this->steps; $this->steps = array(); $this->steps['main'] = $savedSteps['main']; $this->steps['database'] = $savedSteps['database']; $this->steps['offsitedirs'] = $offsitedirs; $this->steps['setup'] = $savedSteps['setup']; $this->steps['finalise'] = $savedSteps['finalise']; } // Do I have a site setup step? $fileNameMain = APATH_INSTALLATION . '/angie/controllers/setup.php'; $fileNameAlt = APATH_INSTALLATION . '/angie/platform/controllers/setup.php'; if (!@file_exists($fileNameAlt)) { $fileNameAlt = APATH_INSTALLATION . '/platform/controllers/setup.php'; } if (!@file_exists($fileNameAlt) && !@file_exists($fileNameMain)) { unset($this->steps['setup']); } $fileNameMain = APATH_INSTALLATION . '/angie/platform/steps.php'; $fileNameAlt = APATH_INSTALLATION . '/platform/steps.php'; if (@file_exists($fileNameMain)) { @(include_once $fileNameMain); } elseif (@file_exists($fileNameAlt)) { @(include_once $fileNameAlt); } if (class_exists('PlatformSteps')) { $platformSteps = new PlatformSteps(); if (method_exists($platformSteps, 'additionalSteps')) { $steps = $platformSteps->additionalSteps($this->steps); if (is_array($steps) && !empty($steps)) { $this->steps = $steps; } } } // @todo Load additional steps $this->input->setData($data); }
/** * Try to read app/etc/local.xml */ public function getconfig() { // Load the default configuration and save it to the session $data = $this->input->getData(); $model = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container); $this->input->setData($data); $this->container->session->saveData(); // Try to load the configuration from the site's configuration.php $filename = APATH_SITE . '/app/etc/local.xml'; if (file_exists($filename)) { $vars = $model->loadFromFile($filename); foreach ($vars as $k => $v) { $model->set($k, $v); } $this->container->session->saveData(); echo json_encode(true); } else { echo json_encode(false); } }
/** * This method allows to update the slave directories with the new hostname. It's never invoked inside ANGIE, * it's only used by UNiTE */ public function updateslavedirectories() { /** @var AngieModelDrupal7Configuration $configModel */ $configModel = AModel::getAnInstance('Configuration', 'AngieModel'); /** @var AngieModelDrupal7Setup $setupModel */ $setupModel = AModel::getAnInstance('Setup', 'AngieModel'); $host = $this->input->getString('host', 'SERVER'); // Do I have a multi-site environment? If so I have to display the setup page several times $directories = $configModel->getSettingsFolders(); // We have to update foreach ($directories as $directory) { // Skip the default directory if ($directory == 'default') { continue; } // Wait, before adding such directory to the stack, I have to update them with the new domain name // ie from oldsite.local.slave to newsite.com.slave $setupModel->updateSlaveDirectory(APATH_ROOT . '/sites/' . $directory, $host); } echo json_encode(true); }
/** * Try to read configuration.php */ public function getconfig() { // Load the default configuration and save it to the session $data = $this->input->getData(); /** @var AngieModelConfiguration $model */ $model = AModel::getAnInstance('Configuration', 'AngieModel'); $this->input->setData($data); ASession::getInstance()->saveData(); // Try to load the configuration from the site's configuration.php $filename = APATH_SITE . '/configuration.php'; if (file_exists($filename)) { $vars = $model->loadFromFile($filename); foreach ($vars as $k => $v) { $model->set($k, $v); } ASession::getInstance()->saveData(); echo json_encode(true); } else { echo json_encode(false); } //AApplication::getInstance()->close(); }
/** * Adds additional steps for this installer * * @param array $steps * * @return mixed */ public function additionalSteps(array $steps) { // Let's double check that we really have the sites folder if (!is_dir(APATH_ROOT . '/sites')) { return $steps; } /** @var AngieModelDrupal7Configuration $configModel */ $configModel = AModel::getAnInstance('Configuration', 'AngieModel'); /** @var AngieModelDrupal7Setup $setupModel */ $setupModel = AModel::getAnInstance('Setup', 'AngieModel'); // Do I have a multi-site environment? If so I have to display the setup page several times $extraSetup = array(); $directories = $configModel->getSettingsFolders(); // We have to update foreach ($directories as $directory) { // Skip the default directory if ($directory == 'default') { continue; } // Wait, before adding such directory to the stack, I have to update them with the new domain name // ie from oldsite.local.slave to newsite.com.slave $directory = $setupModel->updateSlaveDirectory(APATH_ROOT . '/sites/' . $directory); $extraSetup[] = basename($directory); } if ($extraSetup) { // I have to manually add the default "setup" $steps['setup'][] = 'default'; // Now I can add the extra steps $steps['setup'] = array_merge($steps['setup'], $extraSetup); } // Do I have an alias file? If so let's add the step so the user can change it if (file_exists(APATH_ROOT . '/sites/sites.php')) { $finalise = array_pop($steps); $steps['updatealias'] = null; $steps['finalise'] = $finalise; } return $steps; }
/** * Internal method to get the default replacements for the main site URL * * @param AngieModelWordpressConfiguration $config The configuration model * * @return array Any replacements to add */ private function getDefaultReplacementsForMainSite($config) { $replacements = array(); // These values are stored inside the session, after the setup step $old_url = $config->get('oldurl'); $new_url = $config->get('homeurl'); if ($old_url == $new_url) { return $replacements; } // Let's get the reference of the previous absolute path /** @var AngieModelBaseMain $mainModel */ $mainModel = AModel::getAnInstance('Main', 'AngieModel', array(), $this->container); $extra_info = $mainModel->getExtraInfo(); if (isset($extra_info['root']) && $extra_info['root']) { $old_path = rtrim($extra_info['root']['current'], '/'); $new_path = rtrim(APATH_SITE, '/'); $replacements[$old_path] = $new_path; } // Replace the absolute URL to the site $replacements[$old_url] = $new_url; // If the relative path to the site is different, replace it too. $oldUri = new AUri($old_url); $newUri = new AUri($new_url); $oldPath = $oldUri->getPath(); $newPath = $newUri->getPath(); if ($oldPath != $newPath) { $replacements[$oldPath] = $newPath; return $replacements; } return $replacements; }
<?php /** * @package angi4j * @copyright Copyright (C) 2009-2016 Nicholas K. Dionysopoulos. All rights reserved. * @author Nicholas K. Dionysopoulos - http://www.dionysopoulos.me * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL v3 or later */ defined('_AKEEBA') or die; $data = $this->input->getData(); /** @var AngieModelSteps $stepsModel */ $stepsModel = AModel::getAnInstance('Steps', 'AngieModel', array(), $this->container); $this->input->setData($data); $crumbs = $stepsModel->getBreadCrumbs(); $i = 0; ?> <?php if (isset($helpurl) && !empty($helpurl) || isset($videourl) && !empty($videourl)) { ?> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <?php if (isset($helpurl) && !empty($helpurl)) { ?> <?php echo AText::_('GENERIC_LBL_WHATTODONEXT'); ?> <a href="<?php echo $helpurl; ?>
private function getStoreName() { $siteName = ''; $version = $this->container->session->get('version'); /** @var AngieModelDatabase $model */ $model = AModel::getAnInstance('Database', 'AngieModel', array(), $this->container); $keys = $model->getDatabaseNames(); $firstDbKey = array_shift($keys); $connectionVars = $model->getDatabaseInfo($firstDbKey); $name = $connectionVars->dbtype; $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix); $db = ADatabaseFactory::getInstance()->getDriver($name, $options); // On Prestashop 1.4 we have different tables and column names if (version_compare($version, '1.5', 'lt')) { $id = 'id_store'; $table = '#__store'; } else { $id = 'id_shop'; $table = '#__shop'; } // WARNING!! PrestaShop could be configured to support multiple shops. // Of course we should prevent the name changing if we're in such scenario. // At the moment there is no control, we will add it later try { $query = $db->getQuery(true)->select('MIN(' . $db->qn($id) . ')')->from($db->qn($table)); $shopid = $db->setQuery($query)->loadResult(); $query = $db->getQuery(true)->select($db->qn('name'))->from($db->qn($table))->where($db->qn($id) . ' = ' . $shopid); $siteName = $db->setQuery($query)->loadResult(); } catch (Exception $e) { } return $siteName; }
protected function createModel($name, $prefix = '', $config = array()) { $result = null; // Clean the model name $modelName = preg_replace('/[^A-Z0-9_]/i', '', $name); $classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix); $result = AModel::getAnInstance($modelName, $classPrefix, $config, $this->container); return $result; }
public function updatehtaccess() { // Let's build the stack of possible files $files = array(APATH_ROOT . '/.htaccess', APATH_ROOT . '/htaccess.bak'); // Do I want to give more importance to .bak file first? if ($this->input->getInt('bak_first', 0)) { rsort($files); } $fileName = false; foreach ($files as $file) { // Did I found what I'm looking for? if (file_exists($file)) { $fileName = $file; break; } } // No file? Let's stop here if (!$fileName) { return true; } // Get the site's URL /** @var AngieModelWordpressConfiguration $config */ $config = AModel::getAnInstance('Configuration', 'AngieModel', array(), $this->container); $new_url = $config->get('siteurl'); $homeurl = $config->get('homeurl'); $newURI = new AUri($new_url); $path = $newURI->getPath(); // Load the .htaccess in memory $contents = @file_get_contents($fileName); if ($contents === false) { return false; } // Explode its lines $lines = explode("\n", $contents); $contents = ''; $inSection = null; foreach ($lines as $line) { // Fix naughty Windows users' doing $line = rtrim($line, "\r"); // If we are not inside the WordPress section look for the BEGIN signature if (is_null($inSection)) { if (strpos($line, '# BEGIN WordPress') === 0) { $inSection = true; } } elseif ($inSection) { if (strpos($line, '# END WordPress') === 0) { $inSection = false; } elseif (strpos($line, 'RewriteBase ') === 0) { $line = "RewriteBase {$path}"; // If the site is hosted on the domain's root if (empty($path)) { $line = "RewriteBase /"; } } elseif (strpos($line, 'RewriteRule .') === 0) { $line = 'RewriteRule . ' . $path . '/index.php [L]'; } } // Add the line $contents .= "{$line}\n"; } // Write the new .htaccess $fileName = APATH_ROOT . '/.htaccess'; file_put_contents($fileName, $contents); // If the homeurl and siteurl don't match, copy the .htaccess file and index.php in the correct directory if ($new_url != $homeurl) { $homeUri = new AUri($homeurl); $homePath = $homeUri->getPath(); if (strpos($path, $homePath) !== 0) { // I have no clue where to put the files so I'll do nothing at all :s return true; } // $homePath is WITHOUT /wordpress_dir (/foobar); $path is the one WITH /wordpress_dir (/foobar/wordpress_dir) $homePath = ltrim($homePath, '/\\'); $path = ltrim($path, '/\\'); $homeParts = explode('/', $homePath); $siteParts = explode('/', $path); $numHomeParts = count($homeParts); $siteParts = array_slice($siteParts, $numHomeParts); // Relative path from HOME to SITE (WP) root $relPath = implode('/', $siteParts); // How many directories above the root (where we are restoring) is our site's root $levelsUp = count($siteParts); // Determine the path where the index.php and .htaccess files will be written to $targetPath = APATH_ROOT . str_repeat('/..', $levelsUp); $targetPath = realpath($targetPath) ? realpath($targetPath) : $targetPath; // Copy the files if (!@copy(APATH_ROOT . '/.htaccess', $targetPath . '/.htaccess')) { return false; } if (!@copy(APATH_ROOT . '/index.php', $targetPath . '/index.php')) { return false; } // Edit the index.php file $fileName = $targetPath . '/index.php'; $fileContents = @file($fileName); if (empty($fileContents)) { return false; } foreach ($fileContents as $index => $line) { $line = trim($line); if (strstr($line, 'wp-blog-header.php') && strpos($line, 'require') === 0) { $line = "require( dirname( __FILE__ ) . '/{$relPath}/wp-blog-header.php' );"; } $fileContents[$index] = $line; } $fileContents = implode("\n", $fileContents); @file_put_contents($fileName, $fileContents); } return true; }
public static function superusers($selected = null) { $options = array(); $params = AModel::getAnInstance('Setup', 'AngieModel')->getStateVariables(); if (isset($params)) { $superusers = $params->superusers; foreach ($superusers as $sa) { $options[] = self::option($sa->id, $sa->username); } } return self::genericlist($options, 'superuserid', array('onchange' => 'setupSuperUserChange()'), 'value', 'text', $selected); }
/** * Renames the directory containing the old host name to the new one * * @param string $directory Absolute path to the slave directory with the old hostname * @param string $host Force the host to a specific domain. This is used when we're restoring using UNiTE * * @return string */ public function updateSlaveDirectory($directory, $host = 'SERVER') { // No need to continue if the directory is not valid if (!is_dir($directory)) { return $directory; } // First of all, let's get the old hostname /** @var AngieModelDrupal8Main $mainModel */ $mainModel = AModel::getAnInstance('Main', 'AngieModel', array(), $this->container); $extraInfo = $mainModel->getExtraInfo(); // No host information? Well, let's stop here if (!isset($extraInfo['host']) || !$extraInfo['host']) { return $directory; } $uri = AUri::getInstance($host); $oldHost = $extraInfo['host']['current']; $newHost = $uri->getHost(); // If the old host name is not inside the folder name, there's no point in continuing if (strpos($directory, $oldHost) === false) { return $directory; } // Can't fetch the new host? Let's stop here if (!$newHost) { return $directory; } $newDirectory = str_replace($oldHost, $newHost, $directory); if (!rename($directory, $newDirectory)) { return $directory; } // Ok, I have successfully renamed the folder, now I have to update the Configuration model // since it stores all the values using the folder name $oldNamespace = basename($directory); $newNamespace = basename($newDirectory); /** @var AngieModelDrupal8Configuration $configModel */ $configModel = $this->configModel; $configVars = $configModel->getConfigvars(); if (isset($configVars[$oldNamespace])) { // Let's migrate all the values. Old values are still set, but we can live with that foreach ($configVars[$oldNamespace] as $key => $value) { $configModel->set($key, $value, $newNamespace); } } // Finally register the association between the old namespace with the new one // it will be useful if we have a multi database installation, see AngieModelDrupal7Configuration::getDatabase() $configModel->set('hostMapping', array($newNamespace => $oldNamespace), 'default'); return $newDirectory; }
/** * Resets the database connection information of all databases */ public function resetDatabaseConnectionInformation() { $model = AModel::getAnInstance('Database', 'AngieModel'); $databasesIni = $model->getDatabasesIni(); $temp = array(); foreach ($databasesIni as $key => $data) { $data['dbhost'] = ''; $data['dbuser'] = ''; $data['dbpass'] = ''; $data['dbname'] = ''; $model->setDatabaseInfo($key, $data); } $model->saveDatabasesIni(); ASession::getInstance()->set('main.resetdbinfo', true); }