Ejemplo n.º 1
0
 public function install()
 {
     // We need to register the autoloaders for the DB uninstallation to
     // work properly. This would not otherwise be done in the install
     // function.
     ClassLoader::getInstance()->registerPackage($this);
     // We only call this because we want a fresh database when we import
     // the example data there. Do not normally call this!
     $dbm = $this->getDatabaseStructureManager();
     $dbm->uninstallDatabase();
     $pkg = parent::install();
     $this->installSinglePages($pkg);
     $this->installData($pkg);
 }
Ejemplo n.º 2
0
 /**
  * Returns a package's class.
  * @param string $pkgHandle Handle of package
  * @return Package
  */
 public function getClass($pkgHandle)
 {
     $app = \Core::make('app');
     $cache = $app->make('cache/request');
     $item = $cache->getItem('package/class/' . $pkgHandle);
     $cl = $item->get();
     if ($item->isMiss()) {
         $item->lock();
         // loads and instantiates the object
         $cl = \Concrete\Core\Foundation\ClassLoader::getInstance();
         $cl->registerPackageController($pkgHandle);
         $class = '\\Concrete\\Package\\' . camelcase($pkgHandle) . '\\Controller';
         try {
             $cl = $app->make($class);
         } catch (\Exception $ex) {
             $cl = $app->make('Concrete\\Core\\Package\\BrokenPackage', array($pkgHandle));
         }
         $cache->save($item->set($cl));
     }
     return clone $cl;
 }
Ejemplo n.º 3
0
 public function testUpgradedPackageSrcFiles()
 {
     $env = Environment::get();
     $env->clearOverrideCache();
     require 'fixtures/amazing_power.php';
     $package = new \Concrete\Package\AmazingPower\Controller();
     $loader = ClassLoader::getInstance();
     $loader->registerPackage($package);
     $root = dirname(DIR_BASE_CORE . '../');
     @mkdir($root . '/packages/amazing_power/src/ElectricState/Routing', 0777, true);
     @mkdir($root . '/packages/amazing_power/src/Concrete/Captcha', 0777, true);
     @copy(dirname(__FILE__) . '/fixtures/amazing_power/RouteHelper.php', $root . '/packages/amazing_power/src/ElectricState/Routing/RouteHelper.php');
     @copy(dirname(__FILE__) . '/fixtures/amazing_power/AkismetController.php', $root . '/packages/amazing_power/src/Concrete/Captcha/AkismetController.php');
     $class = overrideable_core_class('\\Captcha\\AkismetController', 'Captcha/AkismetController.php', $package->getPackageHandle());
     $this->assertEquals('\\Concrete\\Package\\AmazingPower\\Captcha\\AkismetController', $class);
     $this->assertTrue(class_exists('\\Concrete\\Package\\AmazingPower\\Captcha\\AkismetController'));
     $this->assertTrue(class_exists('\\ElectricState\\AmazingPower\\Routing\\RouteHelper'));
     @unlink($root . '/packages/amazing_power/src/ElectricState/Routing/RouteHelper.php');
     @unlink($root . '/packages/amazing_power/src/Concrete/Captcha/AkismetController.php');
     @rmdir($root . '/packages/amazing_power/src/ElectricState/Routing');
     @rmdir($root . '/packages/amazing_power/src/ElectricState');
     @unlink($root . '/packages/amazing_power/src/Concrete/Captcha');
     @unlink($root . '/packages/amazing_power/src/Concrete');
     @unlink($root . '/packages/amazing_power/src');
     @unlink($root . '/packages/amazing_power');
 }
Ejemplo n.º 4
0
 /**
  * @return Package
  */
 public function install()
 {
     $cl = \Concrete\Core\Foundation\ClassLoader::getInstance();
     $cl->registerPackage($this);
     PackageList::refreshCache();
     $db = Loader::db();
     $dh = Loader::helper('date');
     $v = array($this->getPackageName(), $this->getPackageDescription(), $this->getPackageVersion(), $this->getPackageHandle(), 1, $dh->getOverridableNow());
     $db->query("insert into Packages (pkgName, pkgDescription, pkgVersion, pkgHandle, pkgIsInstalled, pkgDateInstalled) values (?, ?, ?, ?, ?, ?)", $v);
     $pkg = Package::getByID($db->Insert_ID());
     Package::installDB($pkg->getPackagePath() . '/' . FILENAME_PACKAGE_DB);
     $env = Environment::get();
     $env->clearOverrideCache();
     return $pkg;
 }
Ejemplo n.º 5
0
 public function install_package($package)
 {
     $tp = new TaskPermission();
     if ($tp->canInstallPackages()) {
         $p = Package::getClass($package);
         if ($p instanceof BrokenPackage) {
             $this->error->add($p->getInstallErrorMessage());
         } elseif (is_object($p)) {
             $loader = new ClassLoader();
             $loader->registerPackageCustomAutoloaders($p);
             if (!$p->showInstallOptionsScreen() || Loader::helper('validation/token')->validate('install_options_selected')) {
                 $tests = $p->testForInstall();
                 if (is_object($tests)) {
                     $this->error->add($tests);
                 } else {
                     $r = Package::install($p, $this->post());
                     if ($r instanceof ErrorList) {
                         $this->error->add($r);
                         if ($p->showInstallOptionsScreen()) {
                             $this->set('showInstallOptionsScreen', true);
                             $this->set('pkg', $p);
                         }
                     } else {
                         $this->redirect('/dashboard/extend/install', 'package_installed', $r->getPackageID());
                     }
                 }
             } else {
                 $this->set('showInstallOptionsScreen', true);
                 $this->set('pkg', $p);
             }
         } else {
             $this->error->add(t('Package controller file not found.'));
         }
     } else {
         $this->error->add(t('You do not have permission to install add-ons.'));
     }
 }
Ejemplo n.º 6
0
 /**
  * Register package autoloaders. Has to come BEFORE session calls.
  */
 public function setupPackageAutoloaders()
 {
     $pla = \Concrete\Core\Package\PackageList::get();
     $pl = $pla->getPackages();
     $cl = ClassLoader::getInstance();
     /** @var \Package[] $pl */
     foreach ($pl as $p) {
         $p->registerConfigNamespace();
         if ($p->isPackageInstalled()) {
             $pkg = Package::getClass($p->getPackageHandle());
             if (is_object($pkg) && !$pkg instanceof \Concrete\Core\Package\BrokenPackage) {
                 $cl->registerPackage($pkg);
                 $this->packages[] = $pkg;
             }
         }
     }
 }
Ejemplo n.º 7
0
<?php

defined('C5_EXECUTE') or die('Access Denied.');
/**
 * ----------------------------------------------------------------------------
 * Load all composer autoload items.
 * ----------------------------------------------------------------------------
 */
include DIR_APPLICATION . '/bootstrap/autoload.php';
/**
 * ----------------------------------------------------------------------------
 * Load the concrete5 class loader and trigger it.
 * ----------------------------------------------------------------------------
 */
require DIR_BASE_CORE . '/' . DIRNAME_CLASSES . '/Foundation/ClassLoader.php';
require DIR_BASE_CORE . '/' . DIRNAME_CLASSES . '/Foundation/ModifiedPsr4ClassLoader.php';
\Concrete\Core\Foundation\ClassLoader::getInstance();
Ejemplo n.º 8
0
 /**
  * Installs the package info row and installs the database. Packages installing additional content should override this method, call the parent method,
  * and use the resulting package object for further installs.
  * @return Package
  */
 public function install()
 {
     PackageList::refreshCache();
     $db = Database::getActiveConnection();
     $dh = Core::make('helper/date');
     $v = array($this->getPackageName(), $this->getPackageDescription(), $this->getPackageVersion(), $this->getPackageHandle(), 1, $dh->getOverridableNow());
     $db->query("INSERT INTO Packages (pkgName, pkgDescription, pkgVersion, pkgHandle, pkgIsInstalled, pkgDateInstalled) VALUES (?, ?, ?, ?, ?, ?)", $v);
     $pkg = Package::getByID($db->lastInsertId());
     ClassLoader::getInstance()->registerPackage($pkg);
     $pkg->installDatabase();
     $env = Environment::get();
     $env->clearOverrideCache();
     Localization::clearCache();
     return $pkg;
 }
Ejemplo n.º 9
0
 /**
  * Run startup and localization events on any installed packages.
  */
 public function setupPackages()
 {
     $pla = \Concrete\Core\Package\PackageList::get();
     $pl = $pla->getPackages();
     $cl = ClassLoader::getInstance();
     /** @var \Package[] $pl */
     foreach ($pl as $p) {
         $p->registerConfigNamespace();
         if ($p->isPackageInstalled()) {
             $pkg = Package::getClass($p->getPackageHandle());
             if (is_object($pkg) && !$pkg instanceof \Concrete\Core\Package\BrokenPackage) {
                 $cl->registerPackage($pkg);
                 // handle updates
                 if (Config::get('concrete.updates.enable_auto_update_packages')) {
                     $pkgInstalledVersion = $p->getPackageVersion();
                     $pkgFileVersion = $pkg->getPackageVersion();
                     if (version_compare($pkgFileVersion, $pkgInstalledVersion, '>')) {
                         $currentLocale = Localization::activeLocale();
                         if ($currentLocale != 'en_US') {
                             Localization::changeLocale('en_US');
                         }
                         $p->upgradeCoreData();
                         $p->upgrade();
                         if ($currentLocale != 'en_US') {
                             Localization::changeLocale($currentLocale);
                         }
                     }
                 }
                 $pkg->setupPackageLocalization();
                 if (method_exists($pkg, 'on_start')) {
                     $pkg->on_start();
                 }
             }
         }
     }
     Config::set('app.bootstrap.packages_loaded', true);
 }
Ejemplo n.º 10
0
 public function testPackagedSinglePageViewNoPhp()
 {
     $pkg = new Package();
     $pkg->pkgHandle = 'awesome_package';
     $pkg->pkgID = 1;
     $loader = \Concrete\Core\Foundation\ClassLoader::getInstance();
     $loader->registerPackage($pkg);
     $root = realpath(DIR_BASE_CORE . '/../packages');
     @mkdir($root . '/awesome_package/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS . '/testerson', 0777, true);
     @copy(dirname(__FILE__) . '/fixtures/package/foo.php', $root . '/awesome_package/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS . '/testerson/foo.php');
     @mkdir($root . '/awesome_package/' . DIRNAME_PAGES . '/testerson', 0777, true);
     @copy(dirname(__FILE__) . '/fixtures/application/views/foo.php', $root . '/awesome_package/' . DIRNAME_PAGES . '/testerson/foo.php');
     SinglePage::add('/testerson/foo', $pkg);
     $fooPage = Page::getByPath('/testerson/foo');
     $fooPage->pkgHandle = 'awesome_package';
     $controller = $fooPage->getPageController();
     @unlink($root . '/awesome_package/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS . '/testerson/foo.php');
     @rmdir($root . '/awesome_package/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS . '/testerson');
     @rmdir($root . '/awesome_package/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS);
     @unlink($root . '/awesome_package/' . DIRNAME_PAGES . '/testerson/foo.php');
     @rmdir($root . '/awesome_package/' . DIRNAME_PAGES . '/testerson');
     @rmdir($root . '/awesome_package/' . DIRNAME_PAGES);
     @rmdir($root . '/awesome_package');
     $this->assertEquals('Concrete\\Package\\AwesomePackage\\Controller\\SinglePage\\Testerson\\Foo', get_class($controller));
     $this->assertInstanceOf('\\Concrete\\Core\\Page\\Controller\\PageController', $controller);
 }
Ejemplo n.º 11
0
 /**
  * Run startup and localization events on any installed packages.
  */
 public function setupPackages()
 {
     $pla = \Concrete\Core\Package\PackageList::get();
     $pl = $pla->getPackages();
     $cl = ClassLoader::getInstance();
     foreach ($pl as $p) {
         if ($p->isPackageInstalled()) {
             $pkg = Package::getClass($p->getPackageHandle());
             if (is_object($pkg)) {
                 $cl->registerPackage($pkg);
                 // handle updates
                 if (Config::get('concrete.misc.enable_auto_update_packages')) {
                     $pkgInstalledVersion = $p->getPackageVersion();
                     $pkgFileVersion = $pkg->getPackageVersion();
                     if (version_compare($pkgFileVersion, $pkgInstalledVersion, '>')) {
                         $currentLocale = Localization::activeLocale();
                         if ($currentLocale != 'en_US') {
                             Localization::changeLocale('en_US');
                         }
                         $p->upgradeCoreData();
                         $p->upgrade();
                         if ($currentLocale != 'en_US') {
                             Localization::changeLocale($currentLocale);
                         }
                     }
                 }
                 $pkg->setupPackageLocalization();
                 if (method_exists($pkg, 'on_start')) {
                     $pkg->on_start();
                 }
             }
         }
     }
 }
 public function testPackageSrcFiles()
 {
     $env = Environment::get();
     $env->clearOverrideCache();
     $package = new \Package();
     $package->pkgHandle = 'testing';
     $loader = ClassLoader::getInstance();
     $loader->registerPackage($package);
     $root = dirname(DIR_BASE_CORE . '../');
     @mkdir($root . '/packages/testing/src/', 0777, true);
     @copy(dirname(__FILE__) . '/fixtures/RouteHelper.php', $root . '/packages/testing/src/RouteHelper.php');
     $class = new \Concrete\Package\Testing\RouteHelper();
     $this->assertInstanceOf('\\Concrete\\Package\\Testing\\RouteHelper', $class);
     @unlink($root . '/packages/testing/src/RouteHelper.php');
     @rmdir($root . '/packages/testing/src');
     @rmdir($root . '/packages/testing');
 }