示例#1
0
 public function isValid($data)
 {
     $valid = parent::isValid($data);
     // Custom valid
     if ($valid) {
         $params = array();
         foreach ($data as $key => $value) {
             if (false !== strpos($key, '_')) {
                 list($p, $c) = explode('_', $key, 2);
                 if ($p == 'params') {
                     $params[$c] = $value;
                 }
             }
         }
         try {
             $vfs = Engine_Vfs::factory($data['adapter'], $params);
             $vfs->getSystemType();
             // Used to test connection
         } catch (Exception $e) {
             $this->addError('Could not create VFS connection. Error was:');
             $this->addError($e->getMessage());
             return false;
         }
     }
     return $valid;
 }
示例#2
0
 public function getVfs()
 {
     if (null === $this->_vfs) {
         $this->_vfs = Engine_Vfs::factory($this->_vfsConfig['adapter'], $this->_vfsConfig['params']);
         if (!$this->_vfs instanceof Engine_Vfs_Adapter_Abstract) {
             throw new Storage_Model_Exception('Unable to load VFS adapter');
         }
     }
     return $this->_vfs;
 }
示例#3
0
 public function vfsAction()
 {
     // Get vfs config
     $vfsConfig = array();
     $vfsFile = APPLICATION_PATH . '/install/config/vfs.php';
     if (file_exists($vfsFile)) {
         $vfsConfig = (include $vfsFile);
     }
     $this->view->form = $form = new Install_Form_VfsInfo();
     // Get current vfs config
     $vfsConfigCurrent = $this->_session->vfs;
     if (!is_array($vfsConfigCurrent)) {
         $vfsConfigCurrent = array();
     }
     // Adapter type
     $adapterType = $this->_getParam('adapter');
     if (null === $adapterType) {
         if (!empty($vfsConfigCurrent['adapter'])) {
             $adapterType = @$vfsConfigCurrent['adapter'];
         } else {
             $adapterType = @$vfsConfig['adapter'];
         }
     }
     $previousAdapterType = $this->_getParam('previousAdapter');
     // Form
     $this->view->form = $form = new Install_Form_VfsInfo(array('adapterType' => $adapterType));
     // Populate
     if (!$this->getRequest()->isPost() || $adapterType != $previousAdapterType) {
         if (!$adapterType) {
             // Ignore
         } else {
             if ($adapterType == @$vfsConfigCurrent['adapter']) {
                 // Load from session
                 $form->populate($vfsConfigCurrent);
             } else {
                 if ($adapterType == @$vfsConfig['adapter']) {
                     // Load from settings file
                     $form->populate($vfsConfig);
                 } else {
                     $form->populate(array('adapter' => $adapterType));
                 }
             }
         }
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $vfsConfigCurrent = $form->getValues();
     // Try to load adapter
     try {
         $vfs = Engine_Vfs::factory($vfsConfigCurrent['adapter'], $vfsConfigCurrent['config']);
     } catch (Exception $e) {
         $form->addError('Connection error: ' . $e->getMessage());
         return;
     }
     // Try to connect (getResource will force connect)
     try {
         $vfs->getResource();
     } catch (Exception $e) {
         $form->addError('Connection error: ' . $e->getMessage());
         return;
     }
     // Search for target
     $path = null;
     if (!empty($vfsConfigCurrent['config']['search']) && $vfsConfigCurrent['config']['search'] !== '0') {
         $path = $vfs->findJailedPath($vfsConfig['path'], APPLICATION_PATH . '/install/ftp_search_will_look_for_this_file');
         if (!$path) {
             $form->addError('Your installation could not be found. Please double check your connection info and starting path. Your starting path needs to be your SocialEngine path, or a parent directory of it.');
             return;
         }
         $path = dirname(dirname($path));
     } else {
         $path = $vfsConfigCurrent['config']['path'];
     }
     // Verify path
     if (!$vfs->exists($path . '/install/ftp_search_will_look_for_this_file')) {
         $form->addError('Specified path is not a SocialEngine install directory.');
         return;
     }
     // Save config
     $vfsConfigCurrent = $vfsConfig = array('adapter' => $vfsAdapter, 'config' => $vfsConfig);
     $vfsConfigCurrent['config']['path'] = $path;
     $vfs->changeDirectory($path);
     $this->_session->vfsInstance = $vfs;
     $this->_session->vfs = $vfsConfigCurrent;
     // Save for later
     $vfsSettingsData = array('adapter' => $vfsAdapter, 'config' => array_diff_key($vfsConfigCurrent, array('password' => null, 'location' => null, 'search' => null)));
     @file_put_contents(APPLICATION_PATH . '/install/config/vfs.php', '<?php return ' . var_export($vfsSettingsData, true) . '?>');
     return $this->_doSuccessRedirect();
 }
 public function vfsAction()
 {
     // Check for modifications to installer (to prevent problems)
     if (!$this->_checkForModifications()) {
         return;
     }
     // Load the transaction from the cache
     $transaction = $this->_loadTransaction();
     // Get navigation
     $this->view->installNavigation = $this->getInstallNavigation('vfs');
     $adapterType = $this->_getParam('adapter');
     if (null === $adapterType) {
         $adapterType = $this->_session->vfsAdapter;
         if (null === $adapterType) {
             $adapterType = @$this->_vfsSettings['adapter'];
         }
     }
     $previousAdapterType = $this->_getParam('previousAdapter');
     $this->view->form = $form = new Install_Form_VfsInfo(array('adapterType' => $adapterType));
     if (!$this->getRequest()->isPost() || $adapterType != $previousAdapterType) {
         if (!$adapterType) {
             // Ignore
         } else {
             if ($adapterType == @$this->_session->vfsAdapter) {
                 // Load from session
                 $form->populate(array('adapter' => $adapterType, 'config' => $this->_session->vfsConfig));
             } else {
                 if ($adapterType == @$this->_vfsSettings['adapter']) {
                     // Load from settings file
                     $form->populate($this->_vfsSettings);
                 } else {
                     $form->populate(array('adapter' => $adapterType));
                 }
             }
         }
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $values = $form->getValues();
     $vfsAdapter = $values['adapter'];
     $vfsConfig = $values['config'];
     // Try to load adapter
     try {
         $vfs = Engine_Vfs::factory($vfsAdapter, $vfsConfig);
     } catch (Exception $e) {
         $form->addError('Connection error: ' . $e->getMessage());
         return;
     }
     // Try to connect (getResource will force connect)
     try {
         $vfs->getResource();
     } catch (Exception $e) {
         $form->addError('Connection error: ' . $e->getMessage());
         return;
     }
     // Search for target
     $path = null;
     if (!empty($vfsConfig['search']) && $vfsConfig['search'] !== '0') {
         $path = $vfs->findJailedPath($vfsConfig['path'], APPLICATION_PATH . '/install/ftp_search_will_look_for_this_file');
         if (!$path) {
             $form->addError('Your installation could not be found. Please double check your connection info and starting path. Your starting path needs to be your SocialEngine path, or a parent directory of it.');
             return;
         }
         $path = dirname(dirname($path));
     } else {
         $path = $vfsConfig['path'];
     }
     // Verify path
     if (!$vfs->exists($path . '/install/ftp_search_will_look_for_this_file')) {
         $form->addError('Specified path is not a SocialEngine install directory.');
         return;
     }
     // Save config
     $vfsConfig['path'] = $values['config']['path'] = $path;
     $vfs->changeDirectory($path);
     $this->_session->vfsInstance = $vfs;
     $this->_session->vfsAdapter = $vfsAdapter;
     $this->_session->vfsConfig = $vfsConfig;
     $this->_vfsSettings = $values;
     // Save for later
     $vfsSettingsData = array('adapter' => $vfsAdapter, 'config' => array_diff_key($vfsConfig, array('password' => null, 'location' => null, 'search' => null)));
     @file_put_contents(APPLICATION_PATH . '/install/config/vfs.php', '<?php return ' . var_export($vfsSettingsData, true) . '?>');
     // Redirect to next step
     return $this->_helper->redirector->gotoRoute(array('action' => 'perms'));
 }
示例#5
0
 public function indexAction()
 {
     $this->view->form = $form = new Install_Form_VfsInfo();
     // Adapter type
     $adapterType = $this->_getParam('adapter');
     if (null === $adapterType) {
         $adapterType = $this->_session->vfsAdapter;
         if (null === $adapterType) {
             $adapterType = @$this->_vfsSettings['adapter'];
         }
     }
     $previousAdapterType = $this->_getParam('previousAdapter');
     // Return
     $return = $this->_getParam('return');
     if (!$return) {
         if (!empty($_SERVER['HTTP_REFERER']) && false != ($parts = parse_url($_SERVER['HTTP_REFERER'])) && $parts['host'] == $_SERVER['HTTP_HOST']) {
             $return = $parts['path'] . (!empty($parts['query']) ? '?' . $parts['query'] : '');
         }
     }
     if (!$return) {
         $return = $this->view->url(array('controller' => 'manage', 'action' => 'index'));
     }
     // Form
     $this->view->form = $form = new Install_Form_VfsInfo(array('adapterType' => $adapterType));
     // Populate
     if (!$this->getRequest()->isPost() || $adapterType != $previousAdapterType) {
         if (!$adapterType) {
             // Ignore
         } else {
             if ($adapterType == @$this->_session->vfsAdapter) {
                 // Load from session
                 $form->populate(array('adapter' => $adapterType, 'config' => $this->_session->vfsConfig, 'return' => $return));
             } else {
                 if ($adapterType == @$this->_vfsSettings['adapter']) {
                     // Load from settings file
                     $form->populate(array_merge($this->_vfsSettings, array('return' => $return)));
                 } else {
                     $form->populate(array('adapter' => $adapterType, 'return' => $return));
                 }
             }
         }
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $values = $form->getValues();
     $vfsAdapter = $values['adapter'];
     $vfsConfig = $values['config'];
     // Try to load adapter
     try {
         $vfs = Engine_Vfs::factory($vfsAdapter, $vfsConfig);
     } catch (Exception $e) {
         $form->addError('Connection error: ' . $e->getMessage());
         return;
     }
     // Try to connect (getResource will force connect)
     try {
         $vfs->getResource();
     } catch (Exception $e) {
         $form->addError('Connection error: ' . $e->getMessage());
         return;
     }
     // Search for target
     $path = null;
     if (!empty($vfsConfig['search']) && $vfsConfig['search'] !== '0') {
         $path = $vfs->findJailedPath($vfsConfig['path'], APPLICATION_PATH . '/install/ftp_search_will_look_for_this_file');
         if (!$path) {
             $form->addError('Your installation could not be found. Please double check your connection info and starting path. Your starting path needs to be your SocialEngine path, or a parent directory of it.');
             return;
         }
         $path = dirname(dirname($path));
     } else {
         $path = $vfsConfig['path'];
     }
     // Verify path
     if (!$vfs->exists($path . '/install/ftp_search_will_look_for_this_file')) {
         $form->addError('Specified path is not a SocialEngine install directory.');
         return;
     }
     // Save config
     $vfsConfig['path'] = $values['config']['path'] = $path;
     $vfs->changeDirectory($path);
     $this->_session->instance = $vfs;
     $this->_session->adapter = $vfsAdapter;
     $this->_session->config = $vfsConfig;
     $this->_vfsSettings = $values;
     // Save for later
     $vfsSettingsData = array('adapter' => $vfsAdapter, 'config' => array_diff_key($vfsConfig, array('password' => null, 'location' => null, 'search' => null)));
     @file_put_contents(APPLICATION_PATH . '/install/config/vfs.php', '<?php return ' . var_export($vfsSettingsData, true) . '?>');
     // Redirect
     if (!empty($this->_session->return)) {
         $return = $this->_session->return;
         $this->_session->return = null;
     }
     return $this->_helper->redirector->gotoUrl($return, array('prependBase' => false));
 }
示例#6
0
文件: Abstract.php 项目: robeendey/ce
 public function cleanup()
 {
     $manager = $this->getManager();
     $basePath = $manager->getBasePath();
     $tempVfs = Engine_Vfs::factory('system', array('path' => $basePath));
     $archivesPath = $manager->getAbsPath(Engine_Package_Manager::PATH_ARCHIVES);
     $packagesPath = $manager->getAbsPath(Engine_Package_Manager::PATH_PACKAGES);
     $currentPackage = $this->getCurrentPackage();
     $targetPackage = $this->getTargetPackage();
     // Key-based
     if ($currentPackage) {
         try {
             $archivePath = $archivesPath . '/' . $currentPackage->getKey() . '.tar';
             if ($tempVfs->exists($archivePath)) {
                 $tempVfs->unlink($archivePath);
             }
         } catch (Exception $e) {
         }
         try {
             $extractedPath = $packagesPath . '/' . $currentPackage->getKey();
             if ($tempVfs->exists($extractedPath)) {
                 $tempVfs->removeDirectory($extractedPath, true);
             }
         } catch (Exception $e) {
         }
     }
     if ($targetPackage) {
         $archivePath = $archivesPath . '/' . $targetPackage->getKey() . '.tar';
         if ($tempVfs->exists($archivePath)) {
             $tempVfs->unlink($archivePath);
         }
         $extractedPath = $packagesPath . '/' . $targetPackage->getKey();
         if ($tempVfs->exists($extractedPath)) {
             $tempVfs->removeDirectory($extractedPath, true);
         }
     }
     // Source-based
     if ($currentPackage) {
         try {
             $sourcePath = $currentPackage->getSourcePath();
         } catch (Exception $e) {
             $sourcePath = null;
         }
         if ($sourcePath && strpos($sourcePath, dirname($archivesPath)) !== false) {
             $extractedPath = dirname($sourcePath);
             $archivePath = $archivesPath . '/' . basename($extractedPath) . '.tar';
             try {
                 if ($tempVfs->exists($extractedPath)) {
                     $tempVfs->removeDirectory($extractedPath, true);
                 }
             } catch (Exception $e) {
             }
             try {
                 if ($tempVfs->exists($archivePath)) {
                     $tempVfs->unlink($archivePath);
                 }
             } catch (Exception $e) {
             }
         }
     }
     if ($targetPackage) {
         try {
             $sourcePath = $targetPackage->getSourcePath();
         } catch (Exception $e) {
             $sourcePath = null;
         }
         if ($sourcePath && strpos($sourcePath, dirname($archivesPath)) !== false) {
             $extractedPath = dirname($sourcePath);
             $archivePath = $archivesPath . '/' . basename($extractedPath) . '.tar';
             try {
                 if ($tempVfs->exists($extractedPath)) {
                     $tempVfs->removeDirectory($extractedPath, true);
                 }
             } catch (Exception $e) {
             }
             try {
                 if ($tempVfs->exists($archivePath)) {
                     $tempVfs->unlink($archivePath);
                 }
             } catch (Exception $e) {
             }
         }
     }
     return $this;
 }