/** * Die Funktion index() hat überwiegend eine Darstellungsfunktion. Sie ermittelt webserverspezifische * Konstanten wie upload_max_filesize und stellt diese der index.ctp zur Verfügung. * Handelt es sich um einen POST-Request, so wird zusätzlich noch versucht, eine früheren Datenbankzustand wiederherzustellen. * * @see DatabaseManager::import() * @author aloeser * @return void */ public function index() { $maxUploadSize = ini_get('upload_max_filesize'); $maxUploadSizeString = $this->getMaxUploadSizeDisplayFormat($maxUploadSize); $this->set('maxUploadSizeString', $maxUploadSizeString); $maxUploadSizeBytes = $this->return_bytes($maxUploadSize); $this->set('maxUploadSizeBytes', $maxUploadSizeBytes); if ($this->request->is('post')) { //Wurde wirklich eine Datei hochgeladen? if (!isset($this->request->data['User']['File']['tmp_name']) || !is_uploaded_file($this->request->data['User']['File']['tmp_name'])) { $this->Session->setFlash('Fehler beim Hochladen der Datei.<br/>Möglicherweise wurde die maximal erlaubte Dateigröße von ' . $maxUploadSizeString . ' überschritten.', 'alert-box', array('class' => 'alert-error')); return $this->redirect(array('action' => 'index')); } //Ist die hochgeladene Datei zu groß? if ($this->request->data['User']['File']['size'] > $maxUploadSizeBytes) { $this->Session->setFlash('Die Datei ist zu groß.', 'alert-box', array('class' => 'alert-error')); return $this->redirect(array('action' => 'index')); } $result = DatabaseManager::import($this->request->data['User']['File']['tmp_name']); if ($result === true) { //Import erfolgreich $this->Session->setFlash('Wiederherstellung erfolgreich abgeschlossen.', 'alert-box', array('class' => 'alert-success')); return $this->redirect($this->Auth->logout()); } else { $this->Session->setFlash($result, 'alert-box', array('class' => 'alert-error')); } } $actionArray = array('import' => array('text' => 'Zustand wiederherstellen', 'htmlattributes' => array('onClick' => '$( "#ImportDumpForm" ).submit()')), 'export' => array('text' => 'Sicherung durchführen', 'params' => array('controller' => 'backup', 'action' => 'export'))); $this->set('actions', $actionArray); }
/** * Installation erfolgt durch den Import eines Datenbankdumps * Es wird geprüft, ob die Datei korrekt hochgeladen wurde. * Gegebenfalls wird sie an DatabaseManager::import() weitergegeben. * * @see DatabaseManager::import() * @author aloeser * @return void */ public function import() { if ($this->request->is('post')) { $maxUploadSize = ini_get('upload_max_filesize'); $maxUploadSizeString = $this->getMaxUploadSizeDisplayFormat($maxUploadSize); $this->set('maxUploadSizeString', $maxUploadSizeString); $maxUploadSizeBytes = $this->return_bytes($maxUploadSize); $this->set('maxUploadSizeBytes', $maxUploadSize); //Wurde wirklich eine Datei hochgeladen? if (!isset($this->request->data['User']['File']['tmp_name']) || !is_uploaded_file($this->request->data['User']['File']['tmp_name'])) { $this->Session->setFlash('Fehler beim Hochladen der Datei.<br/>Möglicherweise wurde die maximal erlaubte Dateigröße von ' . $maxUploadSizeString . ' überschritten.', 'alert-box', array('class' => 'alert-error')); return $this->redirect(array('action' => 'index')); } //Ist die hochgeladene Datei zu groß? if ($this->request->data['User']['File']['size'] > $maxUploadSizeBytes) { $this->Session->setFlash('Die Datei ist zu groß.', 'alert-box', array('class' => 'alert-error')); return $this->redirect(array('action' => 'index')); } $result = DatabaseManager::import($this->request->data['User']['File']['tmp_name']); if ($result === true) { //Import erfolgreich $this->Session->setFlash('Installation erfolgreich abgeschlossen.', 'alert-box', array('class' => 'alert-success')); return $this->redirect(array('controller' => 'login', 'action' => 'index')); } else { $this->Session->setFlash($result, 'alert-box', array('class' => 'alert-error')); } } return $this->redirect(array('controller' => 'install', 'action' => 'index')); }