コード例 #1
0
ファイル: ApiComponent.php プロジェクト: josephsnyder/Midas
 /**
  * Read in the streamed uploaded file and write it to a temporary file.
  * Returns the name of the temporary file.
  */
 private function _readUploadedFile($prefix)
 {
     UtilityComponent::setTimeLimit(0);
     $inputfile = 'php://input';
     $tmpfile = tempnam(UtilityComponent::getTempDirectory('misc'), $prefix);
     $in = fopen($inputfile, 'rb');
     $out = fopen($tmpfile, 'wb');
     $bufSize = 1024 * 1024;
     $size = 0;
     // read from input and write into file
     while (connection_status() == CONNECTION_NORMAL && ($buf = fread($in, $bufSize))) {
         $size += strlen($buf);
         fwrite($out, $buf);
     }
     fclose($in);
     fclose($out);
     return $tmpfile;
 }
コード例 #2
0
 /** Pre-dispatch routines */
 public function preDispatch()
 {
     UtilityComponent::setTimeLimit(0);
     $enabledModules = Zend_Registry::get('modulesEnable');
     if (Zend_Registry::get('configGlobal')->application->lang != 'en') {
         $translate = new Zend_Translate('csv', BASE_PATH . '/core/translation/fr-main.csv', 'en');
         Zend_Registry::set('translator', $translate);
         $translators = array();
         foreach ($enabledModules as $enabledModule) {
             if (file_exists(BASE_PATH . '/modules/' . $enabledModule . '/translation/fr-main.csv')) {
                 $translators[$enabledModule] = new Zend_Translate('csv', BASE_PATH . '/modules/' . $enabledModule . '/translation/fr-main.csv', 'en');
             } elseif (file_exists(BASE_PATH . '/privateModules/' . $enabledModule . '/translation/fr-main.csv')) {
                 $translators[$enabledModule] = new Zend_Translate('csv', BASE_PATH . '/privateModules/' . $enabledModule . '/translation/fr-main.csv', 'en');
             }
             Zend_Registry::set('translatorsModules', $translators);
         }
     }
     $configs = array();
     foreach ($enabledModules as $enabledModule) {
         if (file_exists(LOCAL_CONFIGS_PATH . '/' . $enabledModule . '.local.ini')) {
             $configs[$enabledModule] = new Zend_Config_Ini(LOCAL_CONFIGS_PATH . '/' . $enabledModule . '.local.ini', 'global');
         } elseif (file_exists(BASE_PATH . '/privateModules/' . $enabledModule . '/configs/module.ini')) {
             $configs[$enabledModule] = new Zend_Config_Ini(BASE_PATH . '/privateModules/' . $enabledModule . '/configs/module.ini', 'global');
         } else {
             $configs[$enabledModule] = new Zend_Config_Ini(BASE_PATH . '/modules/' . $enabledModule . '/configs/module.ini', 'global');
         }
     }
     Zend_Registry::set('configsModules', $configs);
     $forward = $this->getParam('forwardModule');
     $request = $this->getRequest();
     $response = $this->getResponse();
     if (!isset($forward) && $request->getModuleName() == 'default') {
         foreach ($configs as $key => $config) {
             if (file_exists(BASE_PATH . '/modules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php')) {
                 include_once BASE_PATH . '/modules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php';
                 $name = ucfirst($key) . '_' . ucfirst($request->getControllerName()) . 'CoreController';
                 $controller = new $name($request, $response);
                 if (method_exists($controller, $request->getActionName() . 'Action')) {
                     $this->forward($request->getActionName(), $request->getControllerName() . 'Core', $key, array('forwardModule' => true));
                 }
             } elseif (file_exists(BASE_PATH . '/privateModules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php')) {
                 include_once BASE_PATH . '/privateModules/' . $key . '/controllers/' . ucfirst($request->getControllerName()) . 'CoreController.php';
                 $name = ucfirst($key) . '_' . ucfirst($request->getControllerName()) . 'CoreController';
                 $controller = new $name($request, $response);
                 if (method_exists($controller, $request->getActionName() . 'Action')) {
                     $this->forward($request->getActionName(), $request->getControllerName() . 'Core', $key, array('forwardModule' => true));
                 }
             }
         }
     }
     parent::preDispatch();
     if (!$this->isDebug()) {
         $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 86400, 'cache_id_prefix' => 'midas_');
         if (extension_loaded('memcached') || session_save_path() === 'Memcache') {
             $cache = Zend_Cache::factory('Core', 'Libmemcached', $frontendOptions, array());
         } elseif (extension_loaded('memcache')) {
             $cache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, array());
         } else {
             $cacheDir = UtilityComponent::getCacheDirectory() . '/db';
             if (is_dir($cacheDir) && is_writable($cacheDir)) {
                 $backendOptions = array('cache_dir' => $cacheDir);
                 $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
             }
         }
         if (isset($cache)) {
             Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
         }
     }
 }
コード例 #3
0
 /**
  * Index Action (first action when we access the application).
  */
 public function indexAction()
 {
     $this->requireAdminPrivileges();
     // No time limit since import can take a long time
     UtilityComponent::setTimeLimit(0);
     $this->view->title = $this->t('Import');
     $this->view->header = $this->t('Import server-side data');
     $this->assetstores = $this->Assetstore->getAll();
     $this->view->assetstores = $this->assetstores;
     $this->view->importForm = $this->Form->Import->createImportForm($this->assetstores);
     $this->view->assetstoreForm = $this->Form->Assetstore->createAssetstoreForm();
 }
コード例 #4
0
 /**
  * This should become a RESTful controller for instances.
  */
 public function instanceAction()
 {
     UtilityComponent::setTimeLimit(30);
     // in case an exec call hangs for some odd reason
     // TODO just plug this into the RESTful stuff
     $this->disableLayout();
     $this->disableView();
     $pathParams = UtilityComponent::extractPathParams();
     if (empty($pathParams)) {
         throw new Zend_Exception('Must pass instance id as first path parameter', 400);
     }
     $instanceDao = $this->Pvw_Instance->load($pathParams[0]);
     if (!$instanceDao) {
         throw new Zend_Exception('Invalid instance id: ' . $pathParams[0], 400);
     }
     $this->ModuleComponent->Paraview->killInstance($instanceDao);
     echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Instance destroyed'));
 }