Exemple #1
0
 public function run()
 {
     Cache::disableAll();
     $is = new IndexedSearch();
     if ($_GET['force'] == 1) {
         $attributes = \CollectionAttributeKey::getList();
         $attributes = array_merge($attributes, \FileAttributeKey::getList());
         $attributes = array_merge($attributes, \UserAttributeKey::getList());
         foreach ($attributes as $ak) {
             $ak->updateSearchIndex();
         }
         $result = $is->reindexAll(true);
     } else {
         $result = $is->reindexAll();
     }
     if ($result->count == 0) {
         return t('Indexing complete. Index is up to date');
     } else {
         if ($result->count == $is->searchBatchSize) {
             return t('Index partially updated. %s pages indexed (maximum number.) Re-run this job to continue this process.', $result->count);
         } else {
             return t('Index updated.') . ' ' . t2('%d page required reindexing.', '%d pages required reindexing.', $result->count, $result->count);
         }
     }
 }
 /** Executes the job.
  * @throws \Exception Throws an exception in case of errors.
  *
  * @return string Returns a string describing the job result in case of success.
  */
 public function run()
 {
     Cache::disableAll();
     try {
         $instances = array('navigation' => Core::make('helper/navigation'), 'dashboard' => Core::make('helper/concrete/dashboard'), 'view_page' => PermissionKey::getByHandle('view_page'), 'guestGroup' => Group::getByID(GUEST_GROUP_ID), 'now' => new DateTime('now'), 'ak_exclude_sitemapxml' => CollectionAttributeKey::getByHandle('exclude_sitemapxml'), 'ak_sitemap_changefreq' => CollectionAttributeKey::getByHandle('sitemap_changefreq'), 'ak_sitemap_priority' => CollectionAttributeKey::getByHandle('sitemap_priority'));
         $instances['guestGroupAE'] = array(GroupPermissionAccessEntity::getOrCreate($instances['guestGroup']));
         if (\Core::make('multilingual/detector')->isEnabled()) {
             $instances['multilingualSections'] = MultilingualSection::getList();
         } else {
             $instances['multilingualSections'] = array();
         }
         $xml = '<?xml version="1.0" encoding="' . APP_CHARSET . '"?>';
         $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
         if ($instances['multilingualSections']) {
             $xml .= ' xmlns:x="http://www.w3.org/1999/xhtml"';
         }
         $xml .= ' />';
         $xmlDoc = new SimpleXMLElement($xml);
         $rs = Database::get()->query('SELECT cID FROM Pages');
         while ($row = $rs->FetchRow()) {
             self::addPage($xmlDoc, intval($row['cID']), $instances);
         }
         $rs->Close();
         $event = new \Symfony\Component\EventDispatcher\GenericEvent();
         $event->setArgument('xmlDoc', $xmlDoc);
         Events::dispatch('on_sitemap_xml_ready', $event);
         $dom = dom_import_simplexml($xmlDoc)->ownerDocument;
         $dom->formatOutput = true;
         $addedPages = count($xmlDoc->url);
         $relName = ltrim(Config::get('concrete.sitemap_xml.file'), '\\/');
         $osName = rtrim(DIR_BASE, '\\/') . '/' . $relName;
         $urlName = rtrim(\Core::getApplicationURL(), '\\/') . '/' . $relName;
         if (!file_exists($osName)) {
             @touch($osName);
         }
         if (!is_writable($osName)) {
             throw new \Exception(t('The file %s is not writable', $osName));
         }
         if (!($hFile = @fopen($osName, 'w'))) {
             throw new \Exception(t('Cannot open file %s', $osName));
         }
         if (!@fwrite($hFile, $dom->saveXML())) {
             throw new \Exception(t('Error writing to file %s', $osName));
         }
         @fflush($hFile);
         @fclose($hFile);
         unset($hFile);
         return t('%1$s file saved (%2$d pages).', sprintf('<a href="%s" target="_blank">%s</a>', $urlName, preg_replace('/^https?:\\/\\//i', '', $urlName)), $addedPages);
     } catch (\Exception $x) {
         if (isset($hFile) && $hFile) {
             @fflush($hFile);
             @ftruncate($hFile, 0);
             @fclose($hFile);
             $hFile = null;
         }
         throw $x;
     }
 }
Exemple #3
0
 /**
  * Fetch from the remote marketplace the latest available versions of the core and the packages.
  * These operations are done only the first time or after at least APP_VERSION_LATEST_THRESHOLD seconds since the previous check.
  *
  * @return string|null Returns the latest available core version (eg. '5.7.3.1').
  * If we can't retrieve the latest version and if this never succeeded previously, this function returns null.
  */
 public static function getLatestAvailableVersionNumber()
 {
     // first, we check session
     $queryWS = false;
     Cache::disableAll();
     $vNum = Config::get('concrete.misc.latest_version', true);
     Cache::enableAll();
     $versionNum = null;
     if (is_object($vNum)) {
         $seconds = strtotime($vNum->timestamp);
         $version = $vNum->value;
         if (is_object($version)) {
             $versionNum = $version->version;
         } else {
             $versionNum = $version;
         }
         $diff = time() - $seconds;
         if ($diff > Config::get('concrete.updates.check_threshold')) {
             // we grab a new value from the service
             $queryWS = true;
         }
     } else {
         $queryWS = true;
     }
     if ($queryWS) {
         $mi = Marketplace::getInstance();
         if ($mi->isConnected()) {
             Marketplace::checkPackageUpdates();
         }
         $update = static::getLatestAvailableUpdate();
         $versionNum = null;
         if (is_object($update)) {
             $versionNum = $update->getVersion();
         }
         if ($versionNum) {
             Config::save('concrete.misc.latest_version', $versionNum);
         } else {
             // we don't know so we're going to assume we're it
             Config::save('concrete.misc.latest_version', APP_VERSION);
         }
     }
     return $versionNum;
 }
 /**
  * Reindexes the search engine.
  */
 public function reindexAll($fullReindex = false)
 {
     Cache::disableAll();
     $db = Loader::db();
     if ($fullReindex) {
         $db->Execute("truncate table PageSearchIndex");
     }
     $pl = new PageList();
     $pl->ignoreAliases();
     $pl->ignorePermissions();
     $pl->sortByCollectionIDAscending();
     $pl->filter(false, '(c.cDateModified > psi.cDateLastIndexed or UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(psi.cDateLastIndexed) > ' . $this->searchReindexTimeout . ' or psi.cID is null or psi.cDateLastIndexed is null)');
     $pl->filter(false, '(ak_exclude_search_index is null or ak_exclude_search_index = 0)');
     $pages = $pl->get($this->searchBatchSize);
     $num = 0;
     foreach ($pages as $c) {
         // make sure something is approved
         $cv = $c->getVersionObject();
         if (!$cv->cvIsApproved) {
             continue;
         }
         $c->reindex($this, true);
         ++$num;
         unset($c);
     }
     $pnum = Collection::reindexPendingPages();
     $num = $num + $pnum;
     Cache::enableAll();
     $result = new stdClass();
     $result->count = $num;
     return $result;
 }
Exemple #5
0
 /**
  * Testing.
  */
 public function on_start()
 {
     if (isset($_POST['locale']) && $_POST['locale']) {
         $loc = Localization::changeLocale($_POST['locale']);
         $this->set('locale', $_POST['locale']);
     }
     Cache::disableAll();
     $this->setRequiredItems();
     $this->setOptionalItems();
     if (\Core::isInstalled()) {
         throw new Exception(t('concrete5 is already installed.'));
     }
     if (!isset($_COOKIE['CONCRETE5_INSTALL_TEST'])) {
         setcookie('CONCRETE5_INSTALL_TEST', '1', 0, DIR_REL . '/');
     }
 }
Exemple #6
0
 /**
  * Testing.
  */
 public function on_start()
 {
     $this->addHeaderItem('<link href="' . ASSETS_URL_CSS . '/views/install.css" rel="stylesheet" type="text/css" media="all" />');
     $this->requireAsset('core/app');
     $this->requireAsset('javascript', 'backstretch');
     $this->requireAsset('javascript', 'bootstrap/collapse');
     if (isset($_POST['locale']) && $_POST['locale']) {
         $loc = Localization::changeLocale($_POST['locale']);
         $this->set('locale', $_POST['locale']);
     }
     Cache::disableAll();
     $this->setRequiredItems();
     $this->setOptionalItems();
     if ($this->app->isInstalled()) {
         throw new Exception(t('concrete5 is already installed.'));
     }
     if (!isset($_COOKIE['CONCRETE5_INSTALL_TEST'])) {
         setcookie('CONCRETE5_INSTALL_TEST', '1', 0, DIR_REL . '/');
     }
     $this->set('backgroundFade', 0);
     $this->set('pageTitle', t('Install concrete5'));
 }
}
$cliconfig = array_merge($_defaults, $cliArguments);
// Configurations
require $cliconfig['core'] . "/bootstrap/configure.php";
// Autoloader
require $cliconfig['core'] . "/bootstrap/autoload.php";
// CMS
$cms = (require $cliconfig['core'] . "/bootstrap/start.php");
// Database connection
\Database::extend('install', function () use($cliconfig) {
    return \Database::getFactory()->createConnection(array('host' => $cliconfig['db-server'], 'user' => $cliconfig['db-username'], 'password' => $cliconfig['db-password'], 'database' => $cliconfig['db-database']));
});
\Database::setDefaultConnection('install');
$cms['config']['database.connections.install'] = array();
// Disable all caches
Cache::disableAll();
// Install data setup
$passHash = new PasswordHash(Config::get('concrete.user.password.hash_cost_log2'), Config::get('concrete.user.password.hash_portable'));
define('INSTALL_USER_EMAIL', $cliconfig['admin-email']);
define('INSTALL_USER_PASSWORD_HASH', $passHash->HashPassword($cliconfig['admin-password']));
define('INSTALL_STARTING_POINT', $cliconfig['starting-point']);
define('SITE', $cliconfig['site']);
$startingPoint = StartingPointPackage::getClass(INSTALL_STARTING_POINT);
$routines = $startingPoint->getInstallRoutines();
// Redefine the error handlers, overriding any registered by C5
set_error_handler('customErrorHandler');
foreach ($routines as $r) {
    fwrite(STDOUT, sprintf("%s: %s \n", $r->getProgress(), $r->getText()));
    call_user_func(array($startingPoint, $r->getMethod()));
}
fwrite(STDOUT, "!!!!!! Installation Complete: OK !!!!!!\n");
 /**
  * Returns true if the cache is enabled, false if not
  * @return bool
  */
 public function isEnabled()
 {
     return parent::isEnabled();
 }