Exemplo n.º 1
0
 /**
  * 
  * @access public
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $script
  */
 public function scriptRunner($script)
 {
     $error = false;
     $errorStack = array();
     set_time_limit(300);
     if ($script != null) {
         $parameters = array();
         $options = array('argv' => array(0 => 'Script ' . $script), 'output_mode' => 'log_only');
         try {
             $scriptName = 'app\\scripts\\' . $script;
             new $scriptName(array('parameters' => $parameters), $options);
             $error = false;
         } catch (\Exception $e) {
             Logger::e('Error occurs during update ' . $e->getMessage());
             $error = true;
             $errorStack[] = 'Error in script ' . $script . ' ' . $e->getMessage();
         }
         if ($error) {
             echo json_encode(array('success' => 0, 'failed' => $errorStack));
         } else {
             echo json_encode(array('success' => 1, 'failed' => array()));
         }
     } else {
         echo json_encode(array('success' => 0, 'failed' => array('not scriptname provided')));
     }
 }
 /**
  * (non-PHPdoc)
  * @see \OatBox\Common\ScriptRunner::run()
  */
 public function run()
 {
     $service = UpdateService::getInstance();
     $extManifests = $service->getUpdateManifests();
     $releaseManifest = $service->getReleaseManifest();
     $oldRootPath = $releaseManifest['old_root_path'];
     foreach ($extManifests as $ext => $update) {
         Logger::t('Moving Folder ' . $ext);
         File::move($oldRootPath . $ext, DIR_DATA . 'old/' . $ext, false);
     }
     $rootFiles = array('.htaccess', 'index.php', 'favicon.ico', 'fdl-1.3.txt', 'gpl-2.0.txt', 'license', 'version', 'readme.txt');
     foreach ($rootFiles as $file) {
         if (is_file($oldRootPath . $file)) {
             Logger::t('Moving File ' . $file);
             File::move($oldRootPath . $file, DIR_DATA . 'old/' . $file, false);
         } else {
             Logger::w('File not found : ' . $file);
         }
     }
 }
 public function execute()
 {
     $module = $this->context->getModuleName();
     $action = $this->context->getActionName();
     // if module exist include the class
     if ($module !== null) {
         $exptectedPath = DIR_APP . DIR_ACTIONS . $module . '.php';
         if (file_exists($exptectedPath)) {
             require_once $exptectedPath;
         } else {
             throw new ActionEnforcingException("Module '" . Helpers\Camelizer::firstToUpper($module) . "' does not exist in {$exptectedPath}.", $this->context->getModuleName(), $this->context->getActionName());
         }
         if (defined('ROOT_PATH')) {
             $root = realpath(ROOT_PATH);
         } else {
             $root = realpath($_SERVER['DOCUMENT_ROOT']);
         }
         if (preg_match("/^\\//", $root) && !preg_match("/\\/\$/", $root)) {
             $root .= '/';
         } else {
             if (!preg_match("/\\\$/", $root)) {
                 $root .= '\\';
             }
         }
         $relPath = str_replace($root, '', realpath(dirname($exptectedPath)));
         $relPath = str_replace('/', '\\', $relPath);
         $className = $relPath . '\\' . $module;
         if (!class_exists($className)) {
             throw new ActionEnforcingException("Unable to load  {$className} in {$exptectedPath}", $this->context->getModuleName(), $this->context->getActionName());
         }
         // File gracefully loaded.
         $this->context->setModuleName($module);
         $this->context->setActionName($action);
         $moduleInstance = new $className();
     } else {
         throw new ActionEnforcingException("No Module file matching requested module.", $this->context->getModuleName(), $this->context->getActionName());
     }
     // if the method related to the specified action exists, call it
     if (method_exists($moduleInstance, $action)) {
         // search parameters method
         $reflect = new \ReflectionMethod($className, $action);
         $parameters = $reflect->getParameters();
         $tabParam = array();
         foreach ($parameters as $param) {
             $tabParam[$param->getName()] = $this->context->getRequest()->getParameter($param->getName());
         }
         // Action method is invoked, passing request parameters as
         // method parameters.
         Common\Logger::t('Invoking ' . get_class($moduleInstance) . '::' . $action, array('GENERIS', 'CLEARRFW'));
         call_user_func_array(array($moduleInstance, $action), $tabParam);
         // Render the view if selected.
         if ($view = $moduleInstance->hasView()) {
             $renderer = $moduleInstance->getRenderer();
             $renderer->setTemplateDir(DIR_APP . DIR_VIEWS);
             $renderer->setAssetsUrl(ROOT_URL . DIR_ASSETS);
             echo $renderer->render();
         }
     } else {
         throw new ActionEnforcingException("Unable to find the appropriate action for Module '{$module}'.", $this->context->getModuleName(), $this->context->getActionName());
     }
 }
Exemplo n.º 4
0
 /**
  * Parse the framework-object requested into the URL
  *
  * @param Request $pRequest 
  */
 protected function resolveRequest($pRequest)
 {
     $request = $pRequest->getRequestURI();
     if (empty($request)) {
         throw new ResolverException('Empty request URI in Resolver');
     }
     if (preg_match('/^\\/\\/+/', $request)) {
         \OatBox\Common\Logger::w('Multiple leading slashes in request URI: ' . $request);
         $request = '/' . ltrim($request, '/');
     }
     $rootUrlPath = $pRequest->getRootSubPath();
     $absPath = parse_url($request, PHP_URL_PATH);
     if (substr($absPath, 0, strlen($rootUrlPath)) != $rootUrlPath) {
         throw new ResolverException('Request Uri ' . $request . ' outside of TAO path ' . ROOT_URL);
     }
     $relPath = substr($absPath, strlen($rootUrlPath));
     $relPath = ltrim($relPath, '/');
     $tab = explode('/', $relPath);
     if (count($tab) > 0) {
         $this->module = isset($tab[0]) && !empty($tab[0]) ? $tab[0] : null;
         $this->action = isset($tab[1]) && !empty($tab[1]) ? $tab[1] : null;
     } else {
         throw new ResolverException('Empty request Uri ' . $request . ' reached resolver');
     }
 }
 /**
  * Short description of method outVerbose
  *
  * @access public
  * @author firstname and lastname of author, <*****@*****.**>
  * @param  string message
  * @param  array options
  * @return mixed
  */
 public function outVerbose($message, $options = array())
 {
     // section 10-13-1-85-2583e310:134ccc56ba1:-8000:00000000000038B7 begin
     Logger::i($message);
     if (isset($this->parameters['verbose']) && $this->parameters['verbose'] === true) {
         $this->out($message, $options);
     }
     // section 10-13-1-85-2583e310:134ccc56ba1:-8000:00000000000038B7 end
 }
Exemplo n.º 6
0
 public function assets($asset)
 {
     if ($this->assetsUrl == null) {
         Common\Logger::w("View's assets not properly configured, check config variable ASSETS_DIR");
         return $asset;
     }
     return $this->assetsUrl . $asset;
 }
 public function migrateDb()
 {
     $sm = $this->connection->getSchemaManager();
     $queryBuilder = $this->connection->createQueryBuilder();
     $queryBuilder->select('m.modelid', 'm.modeluri')->from('models', 'm');
     // modelid
     $result = $this->connection->executeQuery($queryBuilder->getSql());
     $namespaces = array();
     $newNs = array();
     while ($row = $result->fetch()) {
         $id = $row['modelid'];
         $uri = $row['modeluri'];
         if (substr($uri, -1) != '#') {
             $uri .= '#';
         }
         $namespaces[$id] = $uri;
         $newNs[$this->modelid[$id]] = $uri;
     }
     ksort($newNs);
     $query = 'ALTER TABLE statements CHANGE ' . $this->connection->quoteIdentifier('modelID') . ' ' . $this->connection->quoteIdentifier('modelid') . ' INT( 11 )';
     $result = $this->connection->executeUpdate($query);
     $schema = $sm->createSchema();
     $newSchema = clone $schema;
     $newSchema->dropTable('models');
     $sql = $schema->getMigrateToSql($newSchema, $this->connection->getDatabasePlatform());
     foreach ($sql as $q) {
         $result = $this->connection->executeUpdate($q);
     }
     $schema = $sm->createSchema();
     $newSchema = clone $schema;
     $table = $newSchema->createTable("models");
     $table->addColumn('modelid', "integer", array("notnull" => true));
     $table->addColumn('modeluri', "string", array("length" => 255, "default" => null));
     $table->addOption('engine', 'MyISAM');
     $table->setPrimaryKey(array('modelid'));
     $table->addIndex(array('modeluri'), "idx_models_modeluri");
     $sql = $schema->getMigrateToSql($newSchema, $this->connection->getDatabasePlatform());
     foreach ($sql as $q) {
         $result = $this->connection->executeUpdate($q);
     }
     foreach ($newNs as $id => $ns) {
         $result = $this->connection->insert('models', array('modelid' => $id, 'modeluri' => $ns));
     }
     $orderId = $this->modelid;
     asort($orderId);
     $sanatyCheck = array();
     foreach ($orderId as $old => $new) {
         $tmpvalue = 100 + $new;
         $query = 'update statements set modelid = ' . $tmpvalue . ' where modelid=' . $old;
         $result = $this->connection->executeUpdate($query);
         $sanatyCheck[$newNs[$new]]['first'] = $result;
     }
     for ($i = 101; $i < 120; $i++) {
         $tmpvalue = $i - 100;
         $query = 'update statements set modelid = ' . $tmpvalue . ' where modelid=' . $i;
         $result = $this->connection->executeUpdate($query);
         if (isset($newNs[$tmpvalue])) {
             $sanatyCheck[$newNs[$tmpvalue]]['second'] = $result;
         }
     }
     // var_dump($sanatyCheck);
     Logger::d('Update database completed');
     // echo 'plop';
 }
 /**
  *
  * @access
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param unknown $ext
  * @return boolean
  */
 public function unShield($ext)
 {
     $releaseManifest = $this->getReleaseManifest();
     $extFolder = $releaseManifest['old_root_path'] . $ext;
     if (!is_file($extFolder . '/htaccess.1')) {
         Logger::d('Previous lock, htaccess.1 do not exits something new extension');
         return true;
     }
     if (unlink($extFolder . '/.htaccess')) {
         return File::move($extFolder . '/htaccess.1', $extFolder . '/.htaccess', false);
     } else {
         Logger::e('Fail to remove htaccess in ' . $ext . ' . You may copy by hand file htaccess.1');
         return false;
     }
 }
Exemplo n.º 9
0
 /**
  * Copy a file from source to destination, may be done recursively and may ignore system files
  *
  * @access public
  * @author Lionel Lecaque, <*****@*****.**>
  * @param string source
  * @param string destination
  * @param boolean recursive
  * @param boolean ignoreSystemFiles
  * @return boolean
  */
 public static function copy($source, $destination, $recursive = true, $ignoreSystemFiles = true)
 {
     $returnValue = (bool) false;
     // Check for System File
     $basename = basename($source);
     if ($basename[0] == '.' && $ignoreSystemFiles == true) {
         return false;
     }
     // Check for symlinks
     if (is_link($source)) {
         return symlink(readlink($source), $destination);
     }
     // Simple copy for a file
     if (is_file($source)) {
         // get path info of destination.
         $destInfo = pathinfo($destination);
         if (isset($destInfo['dirname']) && !is_dir($destInfo['dirname'])) {
             if (!mkdir($destInfo['dirname'], 0777, true)) {
                 return false;
             }
         }
         return copy($source, $destination);
     }
     // Make destination directory
     if ($recursive == true) {
         if (!is_dir($destination)) {
             // 0777 is default. See mkdir PHP Official documentation.
             mkdir($destination, 0777, true);
         }
         // Loop through the folder
         $dir = dir($source);
         if ($dir == false) {
             Logger::w('Source ' . $source . ' not found');
         } else {
             while (false !== ($entry = $dir->read())) {
                 // Skip pointers
                 if ($entry == '.' || $entry == '..') {
                     continue;
                 }
                 // Deep copy directories
                 self::copy("{$source}/{$entry}", "{$destination}/{$entry}", $recursive, $ignoreSystemFiles);
             }
             // Clean up
             $dir->close();
         }
         return true;
     } else {
         return false;
     }
     return (bool) $returnValue;
 }