Exemplo n.º 1
0
 public function view()
 {
     $error = \Core::make('helper/validation/error');
     $r = $this->item->download();
     if ($r != false) {
         $error->add($r);
     }
     if (!$error->has()) {
         $pkg = PackageService::getByHandle($this->item->getHandle());
         if (is_object($pkg)) {
             $tests = $pkg->testForInstall();
             if (is_object($tests)) {
                 $error->add($tests);
             } else {
                 $p = PackageService::getClass($this->item->getHandle());
                 try {
                     $p->install();
                 } catch (\Exception $e) {
                     $error->add($e->getMessage());
                 }
             }
         }
     }
     $this->set('error', $error);
     $this->set('mri', $this->item);
 }
Exemplo n.º 2
0
 public function do_update($pkgHandle = false)
 {
     $tp = new TaskPermission();
     if ($tp->canInstallPackages()) {
         if ($pkgHandle) {
             $pkg = \Concrete\Core\Support\Facade\Package::getClass($pkgHandle);
             $r = $pkg->testForInstall(false);
             if (is_object($r)) {
                 $this->error->add($r);
             } else {
                 $p = Package::getByHandle($pkgHandle);
                 $loc = Localization::getInstance();
                 $loc->pushActiveContext('system');
                 try {
                     $p->upgradeCoreData();
                     $p->upgrade();
                     $loc->popActiveContext();
                     $this->set('message', t('The package has been updated successfully.'));
                 } catch (Exception $e) {
                     $loc->popActiveContext();
                     $this->error->add($e);
                 }
             }
         }
     }
     $this->view();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = \Database::connection();
     $em = $db->getEntityManager();
     $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
     $cacheDriver->flushAll();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemas = [];
     /**
      * @var $sm MySqlSchemaManager
      */
     $sm = $db->getSchemaManager();
     $dbSchema = $sm->createSchema();
     // core xml tables
     $schemas[] = Schema::getCoreXMLSchema();
     // core entities
     $sm = new DatabaseStructureManager($em);
     $entities = $sm->getMetadatas();
     $schemas[] = $tool->getSchemaFromMetadata($entities);
     // core, application and package block types
     $env = Environment::get();
     $list = new BlockTypeList();
     $list->includeInternalBlockTypes();
     foreach ($list->get() as $bt) {
         $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . '/' . FILENAME_BLOCK_DB, $bt->getPackageHandle());
         if ($r->exists()) {
             $parser = Schema::getSchemaParser(simplexml_load_file($r->file));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // packages
     $packages = Package::getInstalledList();
     foreach ($packages as $pkg) {
         $xmlFile = $pkg->getPackagePath() . '/' . FILENAME_BLOCK_DB;
         if (file_exists($xmlFile)) {
             $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // Finalize output.
     $comparator = new \Doctrine\DBAL\Schema\Comparator();
     $saveQueries = array();
     foreach ($schemas as $schema) {
         $schemaDiff = $comparator->compare($dbSchema, $schema);
         $saveQueries = array_merge($saveQueries, $schemaDiff->toSaveSql($db->getDatabasePlatform()));
     }
     $saveQueries = $this->filterQueries($saveQueries);
     if (count($saveQueries)) {
         $output->writeln(t2('%s query found', '%s queries found', count($saveQueries)));
         $i = 1;
         foreach ($saveQueries as $query) {
             $output->writeln(sprintf('%s: %s', $i, $query));
             $i++;
         }
     } else {
         $output->writeln(t('No differences found between schema and database.'));
     }
 }
Exemplo n.º 4
0
 public function view()
 {
     $this->set('latest_version', Update::getLatestAvailableVersionNumber());
     $local = [];
     $remote = [];
     $p = new Permissions();
     if ($p->canInstallPackages()) {
         $local = Package::getLocalUpgradeablePackages();
         $remote = Package::getRemotelyUpgradeablePackages();
     }
     // now we strip out any dupes for the total
     $updates = 0;
     $localHandles = [];
     foreach ($local as $_pkg) {
         ++$updates;
         $localHandles[] = $_pkg->getPackageHandle();
     }
     foreach ($remote as $_pkg) {
         if (!in_array($_pkg->getPackageHandle(), $localHandles)) {
             ++$updates;
         }
     }
     $this->set('updates', $updates);
 }
Exemplo n.º 5
0
 public function package_installed($pkgID = 0)
 {
     $this->set('message', t('The package has been installed.'));
     $this->set('installedPKG', Package::getByID($pkgID));
 }
Exemplo n.º 6
0
 /**
  * @deprecated
  */
 public static function getClass($pkgHandle)
 {
     // this should go through the facade instead
     return \Concrete\Core\Support\Facade\Package::getClass($pkgHandle);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rc = 0;
     try {
         $pkgHandle = $input->getArgument('package');
         $packageOptions = array();
         foreach ($input->getArgument('package-options') as $keyValuePair) {
             list($key, $value) = explode('=', $keyValuePair, 2);
             $key = trim($key);
             if (substr($key, -2) === '[]') {
                 $isArray = true;
                 $key = rtrim(substr($key, 0, -2));
             } else {
                 $isArray = false;
             }
             if ($key === '' || !isset($value)) {
                 throw new Exception(sprintf("Unable to parse the package option '%s': it must be in the form of key=value", $keyValuePair));
             }
             if (isset($packageOptions[$key])) {
                 if (!($isArray && is_array($packageOptions[$key]))) {
                     throw new Exception(sprintf("Duplicated package option '%s'", $key));
                 }
                 $packageOptions[$key][] = $value;
             } else {
                 $packageOptions[$key] = $isArray ? (array) $value : $value;
             }
         }
         $output->write("Looking for package '{$pkgHandle}'... ");
         foreach (Package::getInstalledList() as $installed) {
             if ($installed->getPackageHandle() === $pkgHandle) {
                 throw new Exception(sprintf("The package '%s' (%s) is already installed", $pkgHandle, $installed->getPackageName()));
             }
         }
         $pkg = null;
         foreach (Package::getAvailablePackages() as $available) {
             if ($available->getPackageHandle() === $pkgHandle) {
                 $pkg = $available;
                 break;
             }
         }
         if ($pkg === null) {
             throw new Exception(sprintf("No package with handle '%s' was found", $pkgHandle));
         }
         $output->writeln(sprintf('<info>found (%s).</info>', $pkg->getPackageName()));
         $output->write('Checking preconditions... ');
         $test = $pkg->testForInstall();
         if (is_object($test)) {
             throw new Exception(implode("\n", $test->getList()));
         }
         $output->write('Preconditions good. Installing...');
         $r = Package::install($pkg, []);
         if ($r instanceof ErrorList) {
             throw new Exception(implode("\n", $r->getList()));
         }
         $output->writeln('<info>Package Installed.</info>');
         $swapper = new ContentSwapper();
         if ($swapper->allowsFullContentSwap($pkg) && $input->getOption('full-content-swap')) {
             $output->write('Performing full content swap... ');
             $swapper->swapContent($pkg, array());
             if (method_exists($pkg, 'on_after_swap_content')) {
                 $pkg->on_after_swap_content(array());
             }
             $output->writeln('<info>done.</info>');
         }
     } catch (Exception $x) {
         $output->writeln('<error>' . $x->getMessage() . '</error>');
         $rc = 1;
     }
     return $rc;
 }
Exemplo n.º 8
0
 /**
  * Get the package instance (or null if it's a core library).
  *
  * @return \Concrete\Core\Entity\Package|null
  */
 public function getPackageObject()
 {
     return $this->pkgID ? PackageService::getByID($this->pkgID) : null;
 }
 protected function updatePackage($pkgHandle, OutputInterface $output, $force)
 {
     $output->write("Looking for package '{$pkgHandle}'... ");
     $pkg = null;
     foreach (Package::getInstalledList() as $installed) {
         if ($installed->getPackageHandle() === $pkgHandle) {
             $pkg = $installed;
             break;
         }
     }
     if ($pkg === null) {
         throw new Exception(sprintf("No package with handle '%s' is installed", $pkgHandle));
     }
     $output->writeln(sprintf('<info>found (%s).</info>', $pkg->getPackageName()));
     $output->write('Checking preconditions... ');
     $upPkg = null;
     foreach (Package::getLocalUpgradeablePackages() as $updatable) {
         if ($updatable->getPackageHandle() === $pkgHandle) {
             $upPkg = $updatable;
             break;
         }
     }
     if ($upPkg === null && $force !== true) {
         $output->writeln(sprintf("<info>the package is already up-to-date (v%s)</info>", $pkg->getPackageVersion()));
     } else {
         $test = $pkg->testForInstall(false);
         if (is_object($test)) {
             /**
              * @var $test Error
              */
             throw new Exception(implode("\n", $test->getList()));
         }
         $output->writeln('<info>good.</info>');
         if ($upPkg === null) {
             $output->write(sprintf('Forcing upgrade at v%s... ', $pkg->getPackageVersion()));
             $upPkg = Package::getByHandle($pkgHandle);
         } else {
             $output->write(sprintf('Updating from v%s to v%s... ', $upPkg->getPackageEntity()->getPackageVersion(), $upPkg->getPackageVersion()));
         }
         $upPkg->upgradeCoreData();
         $upPkg->upgrade();
         $output->writeln('<info>done.</info>');
     }
 }
Exemplo n.º 10
0
 public function getAvailableMarketplaceItems($filterInstalled = true)
 {
     $fh = Core::make('helper/file');
     if (!$fh) {
         return array();
     }
     $dbConfig = Core::make('config/database');
     // Retrieve the URL contents
     $csToken = $dbConfig->get('concrete.marketplace.token');
     $csiURL = urlencode(Core::getApplicationURL());
     $url = Config::get('concrete.urls.concrete5') . Config::get('concrete.urls.paths.marketplace.purchases');
     $url .= "?csToken={$csToken}&csiURL=" . $csiURL . "&csiVersion=" . APP_VERSION;
     $json = $fh->getContents($url, Config::get('concrete.marketplace.request_timeout'));
     $addons = array();
     $objects = @Core::make('helper/json')->decode($json);
     if (is_array($objects)) {
         try {
             foreach ($objects as $addon) {
                 $mi = new RemoteItem();
                 $mi->setPropertiesFromJSONObject($addon);
                 $remoteCID = $mi->getRemoteCollectionID();
                 if (!empty($remoteCID)) {
                     $addons[$mi->getHandle()] = $mi;
                 }
             }
         } catch (Exception $e) {
         }
         if ($filterInstalled && is_array($addons)) {
             $handles = Package::getInstalledHandles();
             if (is_array($handles)) {
                 $adlist = array();
                 foreach ($addons as $key => $ad) {
                     if (!in_array($ad->getHandle(), $handles)) {
                         $adlist[$key] = $ad;
                     }
                 }
                 $addons = $adlist;
             }
         }
     }
     return $addons;
 }