Ejemplo n.º 1
0
 public function importAction()
 {
     /* @var $logger Zend_Log */
     $this->_logger = Zend_Registry::get('Zend_Log');
     $console = $this->getConsoleOptions(array('name|n=s' => 'Tell me your name'));
     //$message = 'Hello ' . $console->getOption("name");
     $importer = new Cms_Model_SiteMapImporter();
     $importer->importXls('/work/web-apps/cms2/genesis/docs/specs/sitemap-template.xlsx');
 }
Ejemplo n.º 2
0
 public function importAction()
 {
     if ($this->getRequest()->isPost()) {
         try {
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->addValidator("Count", false, array("min" => 1, "max" => 1))->addValidator("Size", false, array("max" => 1000000))->addValidator("Extension", false, array("extension" => "xlsx", "case" => true));
             $adapter->setDestination(APPLICATION_PATH . "/../tmp/");
             $files = $adapter->getFileInfo();
             foreach ($files as $fieldname => $fileinfo) {
                 if ($adapter->isUploaded($fileinfo["name"]) && $adapter->isValid($fileinfo['name'])) {
                     $extension = substr($fileinfo['name'], strrpos($fileinfo['name'], '.') + 1);
                     $filename = 'file_' . date('Ymdhs') . '.' . $extension;
                     $adapter->addFilter('Rename', array('target' => APPLICATION_PATH . "/../tmp/" . $filename, 'overwrite' => true));
                     $adapter->receive($fileinfo["name"]);
                 }
             }
             if (count($adapter->getMessages()) > 0) {
                 return $this->returnAjaxResult(FALSE, $adapter->getMessages());
             } else {
                 $errors = array();
                 $files = $adapter->getFileInfo();
                 $importer = new Cms_Model_SiteMapImporter();
                 foreach ($files as $file) {
                     $result = $importer->importXls($file['destination'] . "/" . $file['name']);
                     if (!$result) {
                         $errors = $importer->getErrors();
                     }
                 }
                 if (count($errors) > 0) {
                     foreach ($errors as $error) {
                         $message[] = $error;
                     }
                     return $this->returnAjaxResult(FALSE, $message);
                 } else {
                     return $this->returnAjaxResult(TRUE, $this->translate('Sitemap successfully imported.'));
                 }
             }
         } catch (Exception $ex) {
             return $this->returnAjaxResult(FALSE, $ex->getMessage());
         }
     } else {
         return $this->returnAjaxResult(FALSE, "No file");
     }
     die;
 }