public static function dialplan($number) { if (get_called_class() != 'FreeSwitch_Feature_Driver') { throw new featureException('Subclass of Freeswitch Feature Driver called but the Dialplan function was not overwritten', -99); } $destination = $number['Destination']; $registry = (array) $destination['registry']; if ($destination['ftr_package_id'] != 0) { $packageobj = Doctrine::getTable('package')->find($destination['ftr_package_id']); if ($packageobj) { try { if (!($package = Package_Catalog::getInstalledPackage($packageobj->name))) { throw new featureException('Package ' . $packageobj->name . ' not found.', -10); } $driverclass = 'FreeSwitch_ftr' . $destination['ftr_name'] . '_Driver'; try { $driver = new $driverclass(); } catch (Exception $e) { throw new featureException('Unable to find feature class ' . $driverlass); } $driver->dialplan($number); } catch (Package_Catalog_Exception $e) { throw new featureException('Package ' . $packageobj->name . ' not found.', -10); } } else { throw new featureException('Package ' . $destination['ftr_package_id'] . 'Found...', -10); } } }
public static function getDisplayList() { $packageList = Package_Catalog::getPackageList(); $avaliablePackages = array('Upgrade Avaliable' => array(), 'Installed' => array(), 'Uninstalled' => array()); foreach ($packageList as $name => $avaliable) { if (isset($avaliable[self::STATUS_INSTALLED])) { $packages = $avaliable[self::STATUS_INSTALLED]; $package = reset($packages); if (!empty($package['upgrades'])) { $avaliablePackages['Upgrade Avaliable'][$name] = $package; } else { $avaliablePackages['Installed'][$name] = $package; } continue; } $newestPackage = array(); foreach ($avaliable as $status => $packages) { foreach ($packages as $key => $package) { if (empty($newestPackage['version'])) { $newestPackage = $package; continue; } if (Package_Dependency::compareVersion($package['version'], $newestPackage['version'])) { $newestPackage = $package; } } } if (!empty($newestPackage)) { $avaliablePackages['Uninstalled'][$name] = $newestPackage; } } return $avaliablePackages; }
public static function listDependencies() { $catalog = Package_Catalog::getCatalog(); $dependencyList = array(); foreach ($catalog as $id => $package) { $packageName = $package['packageName']; if (!array_key_exists($packageName, $dependencyList)) { $dependencyList[$packageName] = array(); } foreach ($package['required'] as $requirement => $conditions) { switch ($requirement) { case 'not': continue; break; case 'or': foreach ($conditions as $name => $condition) { $dependencyList[$name][] = $packageName; } break; default: $dependencyList[$requirement][] = $packageName; } } } return $dependencyList; }
public static function getPackageMessages($messages, $displayedIdentifier) { $html = ''; if (!($package = Package_Catalog::getPackageByIdentifier($displayedIdentifier))) { return ''; } $avaliable = Package_Catalog::getAvaliableVersions($package['packageName']); $avaliable[$displayedIdentifier] = $package['version']; foreach ($messages as $type => $messageList) { foreach ($avaliable as $identifier => $version) { if (empty($messageList[$identifier])) { continue; } $html .= '<div id="' . strtolower($package['packageName'] . '_' . $type) . '"'; $html .= ' class="'; $html .= ' ' . $type . '_message'; $html .= ' ' . $package['packageName'] . '_message packagemanager index module">'; $html .= __(ucfirst($type)); $html .= '<ul class="' . $type . '_list packagemanager index module">'; foreach ($messageList[$identifier] as $message) { $html .= '<li>' . __($message) . '</li>'; } $html .= '</ul>'; $html .= '</div>'; } } return $html; }
public function getDispositionForm() { $faxprof = Input::instance()->post('faxprofile'); $faxdisp = Doctrine::getTable('FaxDisposition')->find($faxprof['fxp_fxd_id']); if ($faxdisp) { $packageobj = Doctrine::getTable('package')->find($faxdisp['fxd_package_id']); if ($packageobj) { try { if (!($package = Package_Catalog::getInstalledPackage($packageobj->name))) { echo 'Package not ' . $packageobj->name . ' found.'; exit; } $formfile = $package['directory'] . '/views/' . $packageobj->name . '/' . $faxdisp['fxd_name'] . '.php'; kohana::Log('debug', 'Looking for view ' . $formfile); if (file_exists($formfile)) { $featureFormView = new View($packageobj->name . '/' . $faxdisp['fxd_name']); kohana::Log('debug', 'View file found.'); if (isset($faxprof['fxp_id']) && !empty($faxprof['fxp_id']) && $faxprof['fxp_id'] != '') { $faxprofobj = Doctrine::getTable('FaxProfile')->find($faxprof['fxp_id']); } else { $faxprofobj = new FaxProfile(); } $featureFormView->set_global('faxprofile', $faxprofobj); echo $featureFormView->render(TRUE); } else { kohana::Log('debug', 'View file not found.'); } } catch (Package_Catalog_Exception $e) { echo 'Package not ' . $packageobj->name . ' found.'; } } } exit; }
public static function package($path) { Package_Message::log('debug', 'Attempting to import package ' . $path); $filename = basename($path); if (self::is_url($path)) { $path = Package_Import_Remote::fetch($path); } $importPath = MODPATH . pathinfo($path, PATHINFO_FILENAME); if (!class_exists('ZipArchive')) { $return = FALSE; Package_Message::log('debug', 'Attempting to unzip with: /usr/bin/unzip ' . $path . ' -d ' . MODPATH); @system('/usr/bin/unzip ' . $path . ' -d ' . $importPath, $return); if ($return !== 0) { throw new Package_Import_Exception('System does not have zip archive support or could not extract ' . $path); } } else { Package_Message::log('debug', 'Attempting to unzip with: ZipArchive->open(' . $path . ', ZIPARCHIVE::CHECKCONS)'); $zip = new ZipArchive(); if (!($error = $zip->open($path, ZIPARCHIVE::CHECKCONS))) { switch ($error) { case ZIPARCHIVE::ER_EXISTS: throw new Package_Import_Exception('Package archive already exists: ' . $error); case ZIPARCHIVE::ER_INCONS: throw new Package_Import_Exception('Consistency check on the package archive failed: ' . $error); case ZIPARCHIVE::ER_INVAL: throw new Package_Import_Exception('Invalid argument while opening package archive: ' . $error); case ZIPARCHIVE::ER_MEMORY: throw new Package_Import_Exception('Memory allocation failure while opening package archive: ' . $error); case ZIPARCHIVE::ER_NOENT: throw new Package_Import_Exception('Could not locate package archive: ' . $error); case ZIPARCHIVE::ER_NOZIP: throw new Package_Import_Exception('Package archive is not a zip: ' . $error); case ZIPARCHIVE::ER_OPEN: throw new Package_Import_Exception('Cant open package archive: ' . $error); case ZIPARCHIVE::ER_READ: throw new Package_Import_Exception('Package archive read error: ' . $error); case ZIPARCHIVE::ER_SEEK: throw new Package_Import_Exception('Package archive seek error: ' . $error); default: throw new Package_Import_Exception('Unknown error while opening package archive: ' . $error); } } if (is_dir($importPath)) { throw new Package_Import_Exception('Import path `' . $importPath . '` already exists'); } if (!@$zip->extractTo($importPath)) { throw new Package_Import_Exception('Failed to extract package archive ' . $filename . ' or no permissions to unzip to ' . MODPATH); } $zip->close(); } kohana::log('debug', 'Dynamically adding `' . $importPath . '` to kohana'); $loadedModules = Kohana::config('core.modules'); $modules = array_unique(array_merge($loadedModules, array($importPath))); Kohana::config_set('core.modules', $modules); Package_Catalog::disableRemote(); Package_Catalog::buildCatalog(); Package_Catalog::enableRemote(); return $importPath; }
public function finalize($identifier) { $package = &Package_Catalog::getPackageByIdentifier($identifier); $package['status'] = Package_Manager::STATUS_INSTALLED; Package_Catalog_Datastore::export($package); }
public function finalize($identifier) { $package =& Package_Catalog::getPackageByIdentifier($identifier); $package['status'] = Package_Manager::STATUS_INSTALLED; Package_Catalog_Datastore::export($package); Package_Catalog::buildCatalog(); $configureInstance = Package_Catalog::getPackageConfigureInstance($identifier); $configureInstance->finalizeInstall($identifier); }
protected function submitReport($report) { $valid = TRUE; $validation = Bluebox_Controller::$validation; if (empty($report['issue'])) { $validation->add_error('report[issue]', 'Please describe the issue'); $valid = FALSE; } if (empty($report['while'])) { $validation->add_error('report[while]', 'Please describe the cause'); $valid = FALSE; } if (empty($report['contact'])) { $validation->add_error('report[contact]', 'Please provide a method to contact you'); $valid = FALSE; } if (empty($report['error'])) { $validation->add_error('report[error]', 'Please provide the error message'); $valid = FALSE; } if (!$valid) { return FALSE; } if (!empty($report['log'])) { $filename = Kohana::log_directory() . date('Y-m-d') . '.log' . EXT; $offset = -150 * 120; $rs = @fopen($filename, 'r'); $report['log'] = ''; if ($rs !== FALSE) { fseek($rs, $offset, SEEK_END); fgets($rs); while (!feof($rs)) { $buffer = fgets($rs); $report['log'] .= htmlspecialchars($buffer . "\n"); } fclose($rs); } } $allowStats = Kohana::config('core.anonymous_statistics'); if (!empty($allowStats)) { $report['anonymous_id'] = Kohana::config('core.anonymous_id'); Package_Catalog::disableRemote(); Package_Catalog::buildCatalog(); $report['catalog'] = Package_Catalog::getPackageList(); } try { $errorCollector = Kohana::config('errorreporter.collector'); $this->do_post_request($errorCollector, $report); } catch (Exception $e) { message::set($e->getMessage()); $this->returnQtipAjaxForm(NULL); return FALSE; } return TRUE; }
protected static function runCheckMethods($identifier) { $configureInstance = Package_Catalog::getPackageConfigureInstance($identifier); $checkMethods = get_class_methods(get_class($configureInstance)); $checkMethods = array_filter($checkMethods, array(__CLASS__, '_filterCheckMethods')); if (empty($checkMethods) || !is_array($checkMethods)) { return; } foreach ($checkMethods as $checkMethod) { try { Package_Message::log('debug', 'Running check method ' . get_class($configureInstance) . '::' . $checkMethod . '();'); $return = call_user_func(array($configureInstance, $checkMethod)); } catch (Exception $e) { //TODO: Still have not figure out how to handle errors... } } }
public function createRepo() { Package_Catalog::disableRemote(); $repoCatalog = Package_Catalog::getCatalog(); foreach ($repoCatalog as $key => &$package) { unset($package['configure_class']); unset($package['directory']); unset($package['upgrades']); unset($package['downgrades']); unset($package['datastore_id']); unset($package['status']); } header('Content-type: text/xml'); echo self::toXml($repoCatalog); flush(); die; }
public static function checkTransaction($name, $operation = NULL) { $transaction = self::$instance->transaction; if (is_null($operation)) { $operation = Package_Manager::OPERATION_INSTALL; } if (empty($transaction[$operation])) { Package_Message::set('No packages queued for operation ' . $operation); throw new Package_Transaction_Exception('No packages queued for operation ' . $operation); } foreach ($transaction[$operation] as $identifier) { $package = Package_Catalog::getPackageByIdentifier($identifier); if ($package['packageName'] == $name) { return $package; } } throw new Package_Transaction_Exception('Transcation does not contain requested package ' . $name); }
function setupCreateEdit() { $catalog = Package_Catalog::getPackageList(); $packagelist = array(); foreach ($catalog as $packagename => $info) { try { if ($package = Package_Catalog::getInstalledPackage($packagename)) { $packagelist[$package['datastore_id']] = $package['displayName']; } } catch (Package_Catalog_Exception $e) { } } asort($packagelist); $packagelist = array(0 => 'Select a Package...') + $packagelist; Event::$data->template->content->packagelist = $packagelist; Event::$data->template->content->usertypelist = array(0 => 'Guest', 40 => 'Restricted', 50 => 'Normal', 60 => 'Power', 70 => 'Restricted Admin', 80 => 'Account Admin', 101 => 'System Admin'); return true; }
public function index() { stylesheet::add('packagemanager'); $messages = array('error' => NULL, 'warning' => NULL, 'notice' => NULL, 'ok' => NULL); $this->view->displayParameters = $this->displayParameters; $this->view->messages = $messages; $this->view->catalog = Package_Manager::getDisplayList(); $messages = Package_Message::get(); if (is_array($messages)) { $this->view->messages = $messages; } else { $this->view->messages = array(); } foreach (Package_Catalog::getCatalog() as $identifier => $package) { kohana::log('debug', $identifier . ' => ' . $package['packageName'] . ' version ' . $package['version']); } Package_Message::clear(); }
public function getFeatureNumberOptionsForm() { $number = Input::instance()->post('number'); if (isset($number['foreign_id'])) { $featureobj = Doctrine::getTable('Feature')->find($number['foreign_id']); if (!$featureobj) { throw new featureException('Feature ' . $featureid . ' not found.'); } $packageobj = Doctrine::getTable('package')->find($featureobj->ftr_package_id); if (!$packageobj) { throw new featureException('Package ' . $featureobj->ftr_package_id . ' not found.'); } if (!($package = Package_Catalog::getInstalledPackage($packageobj->name))) { throw new featureException('Package ' . $packageob->name . ' not found.'); } $viewfile = $package['directory'] . 'views/' . $packageobj->name . '/' . $featureobj->ftr_name . 'Options.php'; if (file_exists($viewfile)) { $featureoptview = new view($pacjageobj->name . '/' . $featureobj->ftr_name . 'Options'); $featureoptview->set_global('number', $number); echo $featureoptview->render(TRUE); } } exit; }
public static function unregister($name, $package, $mode = 'SAFE') { $dispobj = Doctrine::getTable('FaxDispositon')->findOneByname($name); if (!$dispobj) { throw new faxException('Unregistration was attempted on fax disposition "' . $name . '" that is not registered', 0); } $packageobj = null; try { $packageobj = Package_Catalog::getInstalledPackage($package); } catch (Package_Catalog_Exception $e) { } if (!$packageobj && $mode !== 'FORCE') { throw new faxException('The package "' . $package . '" tried to unregister fax disposition "' . $name . '" but the package cannot be found', -1); } $package = $packageobj['datastore_id']; if ($package !== $dispobj->fxd_package_id && $mode !== 'FORCE') { if ($packageobj) { $packagename = $packageobj->name; } else { $packagename = 'NOT FOUND'; } throw new faxException('The package "' . $packagename . '" tried to unregister "' . $dispobj->fxd_name . '" in SAFE mode but did not match the package on file', -2); } $dispobj->delete(); }
/** * Use this function to create a new account, location and user all in one shot. You will get an associative array back containing * the new account, location and user IDs, respectively * @param string $username * @param string $password * @param string $accountName * @param string $locationName * @return array * * TODO: Should we just pass in a list of options, and then pass it around accordingly? */ public static function initializeTenant($options, $users = array()) { // Add the core admin user to the system // TODO: Should check for errors here... Kohana::log('debug', 'Initializing account...'); try { $accountId = self::initializeAccount($options['account']); self::$accountName = $options['account']['name']; } catch (Exception $e) { Kohana::log('error', 'Creating account failed: ' . $e->getMessage()); // Bubble up throw $e; } Kohana::log('debug', 'Initializing location...'); try { $locationId = self::initializeLocation($accountId, $options['location']); } catch (Exception $e) { Kohana::log('error', 'Creating location failed (rolling back tenant): ' . $e->getMessage()); $account = Doctrine::getTable('Account')->find($accountId); $account->delete(); self::$accountName = NULL; // Bubble up throw $e; } Kohana::log('debug', 'Initializing user...'); try { $userId = self::initializeUser($accountId, $locationId, $options['user']); } catch (Exception $e) { Kohana::log('error', 'Creating user failed (rolling back tenant: ' . $e->getMessage()); $location = Doctrine::getTable('Location')->find($locationId); $location->delete(); $account = Doctrine::getTable('Account')->find($accountId); $account->delete(); self::$accountName = NULL; // Bubble up throw $e; } Kohana::log('debug', 'Initializing contexts...'); self::initializeContext($accountId); Kohana::log('debug', 'Scanning packages for tenant-setup routines.'); Package_Catalog::buildCatalog(); $packagelist = Package_Catalog::getPackageList(); foreach ($packagelist as $name => $packages) { if (empty($packages[Package_Manager::STATUS_INSTALLED])) { continue; } $installed = reset($packages[Package_Manager::STATUS_INSTALLED]); try { $configureInstance = Package_Catalog::getPackageConfigureInstance($installed['identifier']); if (method_exists($configureInstance, 'createTenant')) { $configureInstance->createTenant($package); Kohana::log('debug', 'Multi-tenant initialization routine for ' . $package['packageName'] . ' complete'); } } catch (Exception $e) { Kohana::log('error', 'Multi-tenant initialization routine createTenant failed on ' . $package['packageName'] . ': ' . $e->getMessage()); message::set('Unable to initialize tenant!' . '<div class="error_details">' . $e->getMessage() . '</div>'); self::$accountName = NULL; return false; } } Kohana::log('debug', 'Done creating tenant.'); self::$accountName = NULL; self::$created = array('userId' => $userId, 'locationId' => $locationId, 'accountId' => $accountId); // You can get everything you need from here return array('userId' => $userId, 'locationId' => $locationId, 'accountId' => $accountId); }
if (isset($interfaces)) { echo form::label(array('for' => 'externalxfer[route_details][interface]', 'hint' => 'Network interface/IP address to use'), 'Network Interface:'); echo form::dropdown('externalxfer[route_details][interface]', $interfaces); } ?> </div> <div class="field"> <?php echo form::label(array('for' => 'externalxfer[route_details][sipuri]', 'hint' => 'Format is user@domain'), 'SIP URI:'); echo form::input('externalxfer[route_details][sipuri]'); ?> </div> </div> <?php $xmpp = Package_Catalog::getPackageByName('xmpp'); if(isset($xmpp['installed']) && !empty($xmpp['installed']))// == Package_Manager::STATUS_INSTALLED) { ?> <div id="via_xmpp"> <div class="field"> <?php if (isset($xmpps)) { echo form::label(array('for' => 'externalxfer[route_details][xmpp]', 'hint' => 'XMPP to use'), 'XMPP:'); echo form::dropdown('externalxfer[route_details][xmpp]', $xmpps); } ?> </div> <div class="field"> <?php
public function finalize($identifier) { $metadata =& Package_Catalog::getPackageByIdentifier($identifier); Package_Catalog_Datastore::remove($metadata); }
public function finalize($identifier) { $package =& Package_Catalog::getPackageByIdentifier($identifier); unset($package['datastore_id']); Package_Catalog_Datastore::export($package); }
public static function enableRemote() { self::$remote = TRUE; }
protected static function listDependents($parentPackage) { $catalog = Package_Catalog::getCatalog(); $dependents = array(); foreach ($catalog as $id => $package) { if ($package['status'] == Package_Manager::STATUS_UNINSTALLED) { continue; } $dependent = $package['packageName']; foreach ($package['required'] as $requirement => $conditions) { switch ($requirement) { case 'not': continue; case 'or': foreach ($conditions as $name => $condition) { if ($name == $parentPackage) { if (!in_array($dependent, $dependents)) { $dependents[] = $dependent; } } } break; default: if ($requirement == $parentPackage) { if (!in_array($dependent, $dependents)) { $dependents[] = $dependent; } } } } } return $dependents; }
public static function unregister($name, $package, $mode = 'SAFE') { $funcobj = Doctrine::getTable('callmanagerFunction')->findOneByname($name); if (!$funcobj) { $this->_throwError('Unregistration was attempted on function "' . $name . '" that is not registered', 0); } $packageobj = null; try { $packageobj = Package_Catalog::getInstalledPackage($package); } catch (Package_Catalog_Exception $e) { } if (!$packageobj && $mode !== 'FORCE') { $this->_throwError('The package "' . $package . '" tried to unregister function "' . $name . '" but the package cannot be found', -1); } $package = $packageobj['datastore_id']; if ($package !== $funcobj->fcmf_package_id && $mode !== 'FORCE') { if ($packageobj) { $packagename = $packageobj->name; } else { $packagename = 'NOT FOUND'; } $this->_throwError('The package "' . $packagename . '" tried to unregister "' . $funcobj->cmf_name . '" in SAFE mode but did not match the package on file', -2); } $funcobj->delete(); }
protected function prepareUpdateView($baseModel = NULL) { $route_types = array(); $trunkList = array(); $interfaceList = array(); $xmppList = array(); if (class_exists('Trunk')) { $trunks = Doctrine::getTable('Trunk')->findAll(Doctrine::HYDRATE_ARRAY); foreach($trunks as $trunk) { $trunkList[$trunk['trunk_id']] = $trunk['name']; } if (!empty($trunkList)) { $route_types[ExternalXfer::TYPE_TRUNK] = 'via Trunk'; } } if (class_exists('SipInterface')) { $interfaces = Doctrine::getTable('SipInterface')->findAll(Doctrine::HYDRATE_ARRAY); foreach($interfaces as $interface) { $interfaceList[$interface['sipinterface_id']] = $interface['name']; } if (!empty($interfaceList)) { $route_types[ExternalXfer::TYPE_SIP] = 'via SIP URI'; } } if (class_exists('Xmpp')) { $xmpp = Package_Catalog::getPackageByName('xmpp'); if(isset($xmpp['installed']) && !empty($xmpp['installed']))// == Package_Manager::STATUS_INSTALLED) { $xmpps = Doctrine::getTable('Xmpp')->findAll(Doctrine::HYDRATE_ARRAY); foreach($xmpps as $xmpp) { $xmppList[$xmpp['xmpp_id']] = $xmpp['name']; } if(!empty($xmppList)) { $route_types[ExternalXfer::TYPE_XMPP] = 'via XMPP'; } } } if (empty($route_types)) { message::set('No Trunk, XMPP or Sip Interfaces avaliable to route external destinations through!'); $this->returnQtipAjaxForm(NULL); url::redirect(Router_Core::$controller); } $this->view->trunks = $trunkList; $this->view->interfaces = $interfaceList; $this->view->xmpps = $xmppList; $this->view->route_types = $route_types; parent::prepareUpdateView($baseModel); }
private function _freshInstall() { $defaultModules = Kohana::config('config.modules'); Kohana::config_set('core.modules', $defaultModules); // Get the doctrine overlord $manager = Doctrine_Manager::getInstance(); $conn = $manager->getCurrentConnection(); try { // See if we can connect to the DB $conn->connect(); } catch (Doctrine_Connection_Exception $e) { // We could connect earlier, hmmm.... try { Doctrine::createDatabases(); } catch (Exception $e) { // We cant resolve this issue without the user message::set('Unable to establish a connection to ' . $this->session->get('installer.dbName') . '! <div class="error_details">' . $e->getMessage() . '</div>'); return FALSE; } } // See if the DB has any tables in it $tables = $conn->import->listTables(); if (!empty($tables)) { // Yup, there are tables in our soon to be fresh install db, remove them try { $dsn = $conn->getOption('dsn'); $dsn = $manager->parsePdoDsn($dsn); $tmpConn = $conn->getTmpConnection($dsn); $conn->close(); $tmpConn->export->dropDatabase($dsn['dbname']); $tmpConn->export->createDatabase($dsn['dbname']); $manager->closeConnection($tmpConn); $conn->connect(); } catch (Exception $e) { // We cant resolve this issue without the user message::set('Unable to recreate database ' . $this->session->get('installer.dbName') . '! <div class="error_details">' . $e->getMessage() . '</div>'); return FALSE; } } $driver = $this->session->get('installer.tel_driver', 'none'); kohana::log('debug', 'Installer running for driver ' . $driver); $packages = $this->session->get('installer.default_packages', array()); $packages = arr::merge($this->minimumPackages, $packages, array($driver)); try { $transaction = Package_Transaction::beginTransaction(); foreach ($packages as $package) { try { $identifier = Package_Catalog::getFirstAvaliablePackage($package); $transaction->install($identifier); } catch (Exception $e) { kohana::log('error', 'Error during initial install package selection: ' . $e->getMessage()); } } $transaction->commit(); Session::instance()->set('Bluebox_installer.created', Bluebox_Tenant::$created); return TRUE; } catch (Exception $e) { message::set('Installer Error!' . '<div class="error_details">' . $e->getMessage() . '</div>'); return FALSE; } }
protected static function rollback($operation, $identifier, $step, $error) { Package_Message::log('error', 'Package operation ' . $operation . ' failed during ' . $step . ' on package ' . $identifier . ': ' . $error->getMessage()); if ($step == 'validate') { Package_Message::log('debug', 'No rollback action for ' . $operation . ' if we dont get past validate on package ' . $identifier); Package_Operation_Message::set($error->getMessage(), 'error', $identifier); return; } Package_Operation_Message::set($error->getMessage(), 'error', $identifier); switch ($operation) { case Package_Manager::OPERATION_INSTALL: try { Package_Message::log('debug', 'Trying to rollback install via uninstall on package ' . $identifier); Package_Operation_Message::ignoreLogLevels('success'); self::dispatch(Package_Manager::OPERATION_UNINSTALL, $identifier); Package_Operation_Message::acceptAllLogLevels(); } catch (Exception $e) { Package_Operation_Message::set('Error during rollback: ' . $e->getMessage(), 'alert', $identifier); } break; case Package_Manager::OPERATION_MIGRATE: try { if ($package = Package_Catalog::getPackageByIdentifier($identifier)) { if ($installed = Package_Catalog::getInstalledPackage($package['packageName'])) { Package_Message::log('debug', 'Trying to rollback migrate via repair on package ' . $installed['identifier']); Package_Operation_Message::ignoreLogLevels('success'); if (self::dispatch(Package_Manager::OPERATION_REPAIR, $installed['identifier'])) { Package_Operation_Message::set('Rollback of package ' . $installed['displayName'] . ' version ' . $installed['version'] . ' completed', 'info', $identifier); } Package_Operation_Message::acceptAllLogLevels(); } } } catch (Exception $e) { Package_Operation_Message::set('Error during rollback: ' . $e->getMessage(), 'alert', $identifier); } break; case Package_Manager::OPERATION_UNINSTALL: case Package_Manager::OPERATION_REPAIR: case Package_Manager::OPERATION_VERIFY: default: Package_Message::log('debug', 'No rollback action for ' . $operation . ' on package ' . $identifier); break; } }
public function repair($identifier) { $package = Package_Catalog::getPackageByIdentifier($identifier); if (!empty($package['models'])) { $loadedModels = Doctrine::loadModels($package['directory'] . '/models', Doctrine::MODEL_LOADING_CONSERVATIVE); } if (empty($loadedModels)) { return; } foreach ($loadedModels as $modelName) { if (get_parent_class($modelName) != 'Bluebox_Record' and get_parent_class($modelName) != 'Doctrine_Record') { continue; } $migrationDirectory = $package['directory'] . '/migrations/' . $modelName; kohana::log('debug', 'Looking for migrations in `' . $migrationDirectory . '`'); if (is_dir($migrationDirectory)) { try { kohana::log('debug', 'Setting ' . $modelName . ' to version 0 and walking migrations forward to ensure table schema'); $migration = new Bluebox_Migration($migrationDirectory, NULL, strtolower($modelName)); $migration->setCurrentVersion(0); $migration->migrate(); } catch (Exception $e) { kohana::log('alert', 'Alerts during migration, this can USUALLY be ignored: ' . $e->getMessage()); foreach ($migration->getErrors() as $error) { kohana::log('alert', $error->getMessage()); } } } } }