/** * Restore archived files and unserialize mailbox. Removes archive entry */ public function cliRestorePendingsAction() { $archives = $this->getD2EM()->getRepository("\\Entities\\Archive")->findBy(['status' => \Entities\Archive::STATUS_PENDING_RESTORE]); if (!count($archives) && $this->getParam('verbose')) { echo "No pending archives for restoration found.\n"; return; } foreach ($archives as $archive) { //Locking archive by setting it status to restoring if (!$this->_archiveStateChange($archive, \Entities\Archive::STATUS_RESTORING, \Entities\Archive::STATUS_PENDING_RESTORE)) { continue; } $data = unserialize($archive->getData()); if (!isset($data['mailbox']['params']) || !isset($data['mailbox']['className'])) { $this->getLogger()->alert("Bad archive parameters for {$data['mailbox']['params']['username']}"); continue; } $mparams = $data['mailbox']['params']; $homedir = $mparams['homedir']; $maildir = \Entities\Mailbox::cleanMaildir($mparams['maildir']); if ($this->getParam('verbose')) { echo "\nRestoring archive for {$data['mailbox']['params']['username']}... "; } if ($archive->getHomedirFile()) { if (!$this->_untarDir($archive->getHomedirFile(), $homedir)) { $this->getLogger()->notice("ArchiveController::cliRestorePendingsAction - could not untar homedir for {$data['mailbox']['params']['username']}"); continue; } unlink($archive->getHomedirFile()); if ($maildir != $homedir && !$this->_untarDir($archive->getMaildirFile(), $maildir)) { $this->getLogger()->notice("ArchiveController::cliRestorePendingsAction - could not untar maildir for {$data['mailbox']['params']['username']}"); continue; } unlink($archive->getMaildirFile()); } if ($this->getParam('verbose')) { echo "DONE\n"; } $data = $this->_unserialzeMailbox($archive->getData()); $this->notify('archive', 'restorePendings', 'preFlushRestore', $this); $this->getD2EM()->flush(); $this->notify('archive', 'restorePendings', 'postFlushRestore', $this, $data['mailbox']); $this->_notifyAdmin($archive->getArchivedBy(), "archive/email/archive-restored.txt", "Mailbox restored", $data['mailbox']->getUsername()); $this->getD2EM()->remove($this->getD2EM()->getRepository("\\Entities\\Archive")->find($archive->getId())); $this->getD2EM()->flush(); $this->notify('archive', 'restorePendings', 'restored', $this, $data['mailbox']); if ($this->getParam('verbose')) { echo "\n"; } } }