public function tearDown()
 {
     if ($this->documentImported) {
         $ids = Opus_Document::getAllIds();
         $last_id = array_pop($ids);
         $doc = new Opus_Document($last_id);
         $doc->deletePermanent();
     }
     parent::tearDown();
 }
 public function testKeepDocumentNewerThan3Days()
 {
     $this->changeDocumentDateModified(2);
     $this->executeScript('cron-db-clean-temporary.php');
     try {
         $doc = new Opus_Document($this->doc->getId());
         $doc->deletePermanent();
     } catch (Opus_Model_NotFoundException $e) {
         $this->fail("expected existing document.");
     }
 }
 /**
  * Regression Test for OPUSVIER-2646
  */
 public function testFormManipulationForBibliography()
 {
     $this->markTestIncomplete('testing multipart formdata not yet solved');
     $config = Zend_Registry::get('Zend_Config');
     $oldval = null;
     if (isset($config->form->first->bibliographie)) {
         $oldval = $config->form->first->bibliographie;
     }
     $config->form->first->bibliographie = 0;
     $this->request->setMethod('POST')->setPost(array('documentType' => 'demo', 'MAX_FILE_SIZE' => '10240000', 'fileupload' => '', 'uploadComment' => '', 'bibliographie' => '1', 'rights' => '1', 'send' => 'Weiter zum nächsten Schritt'));
     $this->dispatch('/publish/form/upload');
     $session = new Zend_Session_Namespace('Publish');
     // undo config changes
     if (is_null($oldval)) {
         unset($config->form->first->bibliographie);
     } else {
         $config->form->first->bibliographie = $oldval;
     }
     $doc = new Opus_Document($session->documentId);
     $belongsToBibliography = $doc->getBelongsToBibliography();
     $doc->deletePermanent();
     $this->assertResponseCode(200);
     $this->assertNotContains("Es sind Fehler aufgetreten.", $this->response->getBody());
     $this->assertFalse((bool) $belongsToBibliography, 'Expected that document does not belong to bibliography');
 }
Ejemplo n.º 4
0
 /**
  * stores a delivered form as document in the database
  * uses check_array
  */
 public function depositAction()
 {
     if ($this->getRequest()->isPost() !== true) {
         return $this->_redirectTo('index', '', 'index');
     }
     //post content is just checked for buttons
     $post = $this->getRequest()->getPost();
     if (array_key_exists('back', $post)) {
         return $this->_forward('check', 'form');
     }
     if (array_key_exists('abort', $post)) {
         if (isset($this->session->documentId)) {
             try {
                 $document = new Opus_Document($this->session->documentId);
                 $document->deletePermanent();
             } catch (Opus_Model_Exception $e) {
                 $this->getLogger()->err("deletion of document # " . $this->session->documentId . " was not successful", $e);
             }
         }
         return $this->_redirectTo('index', '', 'index');
     }
     $this->view->title = 'publish_controller_index';
     $this->view->subtitle = $this->view->translate('publish_controller_deposit_successful');
     //deposit data is coming from the session
     if (isset($this->session->elements)) {
         foreach ($this->session->elements as $element) {
             $this->depositData[$element['name']] = array('value' => $element['value'], 'datatype' => $element['datatype'], 'subfield' => $element['subfield']);
             $this->log->debug("STORE DATA: " . $element['name'] . ": " . $element['value'] . ", Typ:" . $element['datatype'] . ", Sub:" . $element['subfield']);
         }
     }
     if (isset($this->depositData['send'])) {
         unset($this->depositData['send']);
     }
     try {
         $depositData = new Publish_Model_Deposit($this->session->documentId, $this->log, $this->depositData);
     } catch (Publish_Model_Exception $e) {
         throw new Application_Exception('publish_error_unexpected');
     }
     $this->document = $depositData->getDocument();
     $this->document->setServerState('unpublished');
     try {
         $docId = $this->document->store();
     } catch (Exception $e) {
         // TODO wie sollte die Exception sinnvoll behandelt werden?
         $this->log->err("Document could not be stored successfully: " . $e->getMessage());
         throw new Application_Exception('publish_error_unexpected');
     }
     $this->log->info("Document {$docId} was successfully stored!");
     $this->session->documentId = $docId;
     // Prepare redirect to confirmation action.
     $this->session->depositConfirmDocumentId = $docId;
     $targetAction = 'confirm';
     $targetController = 'deposit';
     $targetModule = 'publish';
     $config = $this->getConfig();
     if (isset($config) and isset($config->publish->depositComplete)) {
         $targetAction = $config->publish->depositComplete->action;
         $targetController = $config->publish->depositComplete->controller;
         $targetModule = $config->publish->depositComplete->module;
     }
     $notification = new Application_Util_Notification($this->log, $config);
     $url = $this->view->url(array("module" => "admin", "controller" => "document", "action" => "index", "id" => $this->document->getId()), null, true);
     $notification->prepareMail($this->document, Application_Util_Notification::SUBMISSION, $this->view->serverUrl() . $url);
     return $this->_redirectToAndExit($targetAction, null, $targetController, $targetModule);
 }
Ejemplo n.º 5
0
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or any later version.
 * OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details. You should have received a copy of the GNU General Public License
 * along with OPUS; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @category    Application
 * @author      Sascha Szott <*****@*****.**>
 * @copyright   Copyright (c) 2008-2012, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id: delete_non-demo_docs.php 10249 2012-02-15 17:00:09Z sszott $
 */
/**
 * Erstellt die Demoinstanz, in der nur die Testdokumente mit den IDs 91 bis 110
 * enthalten sind.
 *
 */
$finder = new Opus_DocumentFinder();
foreach ($finder->ids() as $id) {
    if (intval($id) < 91 || intval($id) > 110) {
        $doc = new Opus_Document($id);
        $doc->deletePermanent();
        echo "document " . $id . " was deleted.\n";
    }
}
$finder = new Opus_DocumentFinder();
echo "done -- num of remaining docs: " . $finder->count() . "\n";
exit;
 * OPUS is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or any later version.
 * OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details. You should have received a copy of the GNU General Public License 
 * along with OPUS; if not, write to the Free Software Foundation, Inc., 51 
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @category    Application
 * @author      Thoralf Klein <*****@*****.**>
 * @copyright   Copyright (c) 2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
// Bootstrapping
require_once dirname(__FILE__) . '/../common/bootstrap.php';
$date = new DateTime();
$dateString = $date->sub(new DateInterval('P2D'))->format('Y-m-d');
$f = new Opus_DocumentFinder();
$f->setServerState('temporary')->setServerDateModifiedBefore($dateString);
foreach ($f->ids() as $id) {
    $d = new Opus_Document($id);
    if ($d->getServerState() == 'temporary') {
        echo "deleting document: {$id}\n";
        $d->deletePermanent();
    } else {
        echo "NOT deleting document: {$id} because it has server state " . $d->getServerState();
    }
}
Ejemplo n.º 7
0
 /**
  * Method displays and checks the second form page. It also concerns for extending and reducing form fields.
  * After correct validation the user is redirected to deposit controller for storing data.
  *
  * @return different types of redirect
  */
 public function checkAction()
 {
     $this->view->languageSelectorDisabled = true;
     $this->view->title = 'publish_controller_index';
     if (isset($this->session->documentType)) {
         $this->view->subtitle = $this->view->translate($this->session->documentType);
     }
     $this->view->requiredHint = $this->view->translate('publish_controller_required_hint');
     if ($this->getRequest()->isPost() === true) {
         $postData = $this->getRequest()->getPost();
         if (!is_null($this->session->additionalFields)) {
             $postData = array_merge($this->session->additionalFields, $postData);
         }
         //abort publish process
         if (array_key_exists('abort', $postData)) {
             if (isset($this->session->documentId)) {
                 try {
                     $document = new Opus_Document($this->session->documentId);
                     $document->deletePermanent();
                 } catch (Opus_Model_Exception $e) {
                     $this->getLogger()->err("deletion of document # " . $this->session->documentId . " was not successful", $e);
                 }
             }
             return $this->_redirectTo('index', '', 'index');
         }
         //go back and change data
         if (array_key_exists('back', $postData)) {
             if (isset($this->session->elements)) {
                 foreach ($this->session->elements as $element) {
                     $postData[$element['name']] = $element['value'];
                 }
             }
         }
         if (!array_key_exists('send', $postData) || array_key_exists('back', $postData)) {
             // A button (not SEND) was pressed => add / remove fields or browse fields (both in form step 2)
             // OR back button (in form step 3)
             if (!array_key_exists('back', $postData)) {
                 // die Session muss nur dann manipuliert werden, wenn im zweiten Schritt ADD/DELETE/BROWSE
                 // durchgeführt wurde
                 try {
                     $this->manipulateSession($postData);
                 } catch (Publish_Model_FormNoButtonFoundException $e) {
                     throw new Application_Exception($e->getTranslateKey());
                 }
             }
             //now create a new form with extended fields
             try {
                 $form = $this->createPublishingSecondForm($postData);
             } catch (Publish_Model_FormSessionTimeoutException $e) {
                 // Session timed out.
                 return $this->_redirectTo('index', '', 'index');
             }
             $this->setViewValues('form', 'check', '#current', $form);
             if (array_key_exists('LegalNotices', $postData) && $postData['LegalNotices'] != '1') {
                 $legalNotices = $form->getElement('LegalNotices');
                 $legalNotices->setChecked(false);
             }
             $this->renderDocumenttypeForm();
             return;
         }
         // SEND was pressed => check the form
         // der nachfolgende Schritt ist erforderlich, da die Selectbox der obersten Ebene einer Collection-Gruppe
         // gegen das Naming Scheme der Selectboxen der tieferen Ebenen verstößt
         foreach ($postData as $key => $value) {
             if (preg_match("/^collId1\\D/", $key) === 1) {
                 $subkey = substr($key, 7);
                 if (!array_key_exists($subkey, $postData)) {
                     $postData[$subkey] = $value;
                 }
             }
         }
         try {
             $form = $this->createPublishingSecondForm($postData);
         } catch (Publish_Model_FormSessionTimeoutException $e) {
             // Session timed out.
             return $this->_redirectTo('index', '', 'index');
         }
         if (!$form->isValid($postData)) {
             $form->setViewValues();
             $this->view->form = $form;
             $this->view->errorCaseMessage = $this->view->translate('publish_controller_form_errorcase');
             $this->renderDocumenttypeForm();
             return;
         }
         // form is valid: move to third form step (confirmation page)
         return $this->showCheckPage($form);
     }
     return $this->_redirectTo('upload');
 }
Ejemplo n.º 8
0
 /**
  * Performs state change on document.
  * @param Opus_Document $document
  * @param string $targetState
  *
  * TODO enforcing permissions and throwing exceptions (OPUSVIER-1959)
  */
 public function changeState($document, $targetState)
 {
     switch ($targetState) {
         case 'deleted':
             $document->delete();
             break;
         case 'removed':
             $document->deletePermanent();
             break;
         default:
             $document->setServerState($targetState);
             $document->store();
             break;
     }
 }