public function viewDetailsAction()
 {
     $updateFileId = (int) $this->_getParam('updateFileId');
     $updateFile = new UpdateFile();
     $updateFile->updateFileId = $updateFileId;
     $updateFile->populate();
     $alterTable = new AlterTable();
     $this->view->name = $updateFile->channel . ': ' . $updateFile->name;
     $this->view->data = $alterTable->generateChanges($updateFile->getUploadFilename());
     $this->render('view-details');
 }
 public function processUploadAction()
 {
     $updateFile = new UpdateFile();
     $uploadDir = $updateFile->getUploadDir();
     if (!is_writable($uploadDir)) {
         $msg = 'tmp directory is not writable';
     } else {
         if (!isset($_FILES['uploadFile'])) {
             $msg = __('No uploaded file');
         } else {
             if ($_FILES['uploadFile']['error'] !== 0) {
                 $msg = __('Error in uploading');
             } else {
                 if (stripos($_FILES['uploadFile']['type'], 'xml') === false) {
                     $msg = __('Invalid file format, must be an XML file.');
                 } else {
                     $file = $_FILES['uploadFile'];
                     $data = file_get_contents($file['tmp_name']);
                     if (!($xml = simplexml_load_string($data))) {
                         $msg = __('Invalid xml format.');
                     }
                 }
             }
         }
     }
     if (isset($msg)) {
         $this->_session->errMsg = $msg;
         throw new Exception($msg);
     }
     $params = $this->_getParam('updateFile');
     $md5sum = md5($data);
     $updateFile->channelId = UpdateFile::USER_CHANNEL_ID;
     $updateFile->channel = UpdateFile::USER_CHANNEL;
     $updateFile->active = 1;
     $updateFile->name = $file['name'];
     $updateFile->mimeType = $file['type'];
     $updateFile->md5sum = $md5sum;
     $updateFile->description = $params['description'];
     $updateFile->dateTime = date('Y-m-d H:i:s');
     $updateFile->persist();
     $filename = $updateFile->getUploadFilename();
     file_put_contents($filename, $data);
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $result = $json->direct(array('updateFileId' => $updateFile->updateFileId), false);
     $this->getResponse()->setHeader('Content-Type', 'text/html');
     $this->view->result = $result;
     $this->render('process-upload');
 }