public function execute() { $this->operationFile = $this->operationFile ? $this->operationFile : $this->kernel->getRootDir() . '/config/operations.xml'; $operationsHandler = new OperationHandler($this->operationFile, $this->logger); $bundles = $this->getBundlesByFqcn(); $operations = $operationsHandler->getOperations(); /** @var \Claroline\BundleRecorder\Operation[] $orderedOperations */ $orderedOperations = []; foreach ($operations as $operation) { if ($operation->getBundleType() === Operation::BUNDLE_CORE) { array_unshift($orderedOperations, $operation); } else { array_push($orderedOperations, $operation); } } foreach ($orderedOperations as $operation) { $installer = $operation->getBundleType() === Operation::BUNDLE_CORE ? $this->baseInstaller : $this->pluginInstaller; if ($operation->getType() === Operation::INSTALL) { $installer->install($bundles[$operation->getBundleFqcn()]); } elseif ($operation->getType() === Operation::UPDATE) { $installer->update($bundles[$operation->getBundleFqcn()], $operation->getFromVersion(), $operation->getToVersion()); } else { // remove or disable package } } rename($this->operationFile, $this->operationFile . '.bup'); }
/** * Here we generate a new operation.xml file. */ public function generateUniqueOperationFile($bundle, $version, $bundleType, $fqcn, $logFile) { $entity = $this->getBundle($bundle); $isInstalled = false; if ($entity) { $oldVersion = $entity->getVersion(); $isInstalled = true; } $operationFilePath = $this->kernelRootDir . "/config/operations.xml"; //remove the old operation file if it exists (maybe it would be better to do a backup). @unlink($operationFilePath); $fileLogger = new \Monolog\Logger('package.update'); $fileLogger->pushHandler(new \Monolog\Handler\StreamHandler($logFile)); $operationHandler = new OperationHandler($operationFilePath, $fileLogger); //generating the operations.xml file $operation = new Operation($isInstalled ? Operation::UPDATE : Operation::INSTALL, $fqcn, $bundleType === 'claroline-plugin' ? Operation::BUNDLE_PLUGIN : Operation::BUNDLE_CORE); if (isset($entity)) { $operation->setFromVersion($oldVersion); } $operation->setToVersion($version); $operation->setDependencies(array()); $operationHandler->addOperation($operation, false); }
$value = Yaml::parse($configDir . '/parameters.yml'); $host = $value['parameters']['database_host']; $dbName = $value['parameters']['database_name']; //dsn driver... hardcoded. Change this if you really need it. //or use the connexion from sf2 $driver = 'mysql'; $dsn = "{$driver}:host={$host};dbname={$dbName}"; $username = $value['parameters']['database_user']; $password = $value['parameters']['database_password']; //create connection $conn = new \PDO($dsn, $username, $password, array()); //Let's use stefk stuff ! $operationFilePath = __DIR__ . "/../../app/config/operations.xml"; //remove the old operation file if it exists (maybe it would be better to do a backup). unlink($operationFilePath); $operationHandler = new OperationHandler($operationFilePath); $detector = new Detector($vendorDir); $bundleHandler = new BundleHandler($configDir . '/bundles.ini'); $recorder = new Recorder(new Detector($vendorDir), new BundleHandler($configDir . '/bundles.ini'), new OperationHandler($configDir . '/operations.xml'), $vendorDir); $recorder->buildBundleFile(); $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); //I need to do that in order to access some services required for the installation... $kernel->boot(); $bundles = array(); //retrieve the current bundles foreach ($recorder->getOperations() as $operation) { $package = $operation->getPackage(); if ($package->getType() === 'claroline-plugin' || $package->getType() === 'claroline-core') { $bundles[] = array('type' => $package->getType(), 'name' => $package->getPrettyName(), 'new_version' => $package->getVersion(), 'is_installed' => false, 'fqcn' => $detector->detectBundle($package->getPrettyName()), 'dependencies' => array($recorder->getDependencies($package))); }