<commit_before><?php
/*=========================================================================
 *
 *  Copyright OSHERA Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

class Journal_SubmitController extends Journal_AppController
{
  function init()
    {

    }

  /** The first step of the submission process is to select an issue */
  function selectissueAction()
    {
    if(!$this->logged)
      {
      $this->renderScript("login.phtml");
      return;
      }
    $this->view->issues = MidasLoader::loadModel("Issue", 'journal')->findActiveIssues();
    foreach($this->view->issues as $key => $issue)
      {
      $community = MidasLoader::loadModel("Folder")->getCommunity(MidasLoader::loadModel("Folder")->getRoot($issue));
      if(isset($_GET['community']) && $community->getKey() !=  $_GET['community']) unset($this->view->issues[$key]);
      if(!$community || !MidasLoader::loadModel("Community")->policyCheck($community, $this->userSession->Dao))
        {
        unset($this->view->issues[$key]);
        }
      }
    }

  /** Form allowing the user to submit an article*/
  function indexAction()
    {
    if(!$this->logged)
      {
      $this->renderScript("login.phtml");
      return;
      }
    // load resource if it exists
    $item_id = $this->_getParam('itemId');
    $revision_id = $this->_getParam('revisionId');
    $issueId = $this->_getParam('issue');
    $isNewSubmission = false;

    // New Revision
    if(isset($item_id))
      {
      $item = MidasLoader::loadModel("Item")->load($item_id);
      if(!MidasLoader::loadModel("Item")->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_WRITE))
        {
        throw new Zend_Exception("Permissions error.");
        }
      $resourceDao = MidasLoader::loadModel("Item")->initDao("Resource", $item->toArray(), "journal");
      $resourceDao->setRevision("New");
      $folder = end($item->getFolders());
      $this->view->json['showlicence'] = 1;
      }
    // Edit
    else if(isset($revision_id))
      {
      $revision = MidasLoader::loadModel("ItemRevision")->load($revision_id);
      if(!$revision)
        {
        throw new Zend_Exception("Unable to find revision.");
        }
      $item = $revision->getItem();
      $resourceDao = MidasLoader::loadModel("Item")->initDao("Resource", $item->toArray(), "journal");
      $resourceDao->setRevision($revision);
      if(!MidasLoader::loadModel("Item")->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_WRITE) )
        {
        throw new Zend_Exception("Permissions error.");
        }
      $folder = end($item->getFolders());
      $this->view->json['showlicence'] = 0;
      }
    // New Resource
    else
      {
      $resourceDao = MidasLoader::newDao('ResourceDao', 'journal');
      $resourceDao->setRevision("New");
      $isNewSubmission = true;
      $folder = MidasLoader::loadModel("Folder")->load($issueId);
      if(!$folder)throw new Zend_Exception("Unable to find issue.");
      $this->view->json['showlicence'] = 1;
      }

    $this->view->issueDao = MidasLoader::loadModel("Folder")->initDao("Issue", $folder->toArray(), "journal");

    // Process form result
    if($this->_request->isPost())
      {
      $resourceDao->setName($_POST['title']);
      $resourceDao->setDescription($_POST['description']);
      $resourceDao->setType($_POST['type']);
      $resourceDao->setThumbnailId(new Zend_Db_Expr('NULL'));
      $anonymousGroup = MidasLoader::loadModel("Group")->load(MIDAS_GROUP_ANONYMOUS_KEY);
      $isNew = !$resourceDao->saved;
      // Create or update resource
      MidasLoader::loadModel("Item")->save($resourceDao);
      $itemRevisionDao = $resourceDao->getRevision();

      // create a new revision
      if(!$itemRevisionDao->saved)
        {
        $itemRevisionDao->setChanges("");
        $itemRevisionDao->setUser_id($this->userSession->Dao->getKey());
        $itemRevisionDao->setDate(date('c'));
        $itemRevisionDao->setLicenseId(null);
        $lastExistingRevision = MidasLoader::loadModel("Item")->getLastRevision($resourceDao);
        MidasLoader::loadModel("Item")->addRevision($resourceDao, $itemRevisionDao);
        if($lastExistingRevision) // If new revision, copy previous data
          {
          $bitstreams = $lastExistingRevision->getBitstreams();
          foreach($bitstreams as $bitstream)
            {
            $type = MidasLoader::loadComponent("Bitstream", "journal")->getType($bitstream);
            $bitstream->saved = false;
            $bitstream->bitstream_id = null;
            if($bitstream->getName() == "")continue;
            MidasLoader::loadModel("ItemRevision")->addBitstream($itemRevisionDao, $bitstream);
            MidasLoader::loadComponent("Bitstream", "journal")->setType($bitstream, $type);
            if($type == BITSTREAM_TYPE_THUMBNAIL) $resourceDao->setLogo($bitstream);
            }

          // Need to copy anything that's not updated on this view
          $resourceDao->setHandle($resourceDao->getHandle());
          $resourceDao->setGithub($resourceDao->getGithub());
          $resourceDao->setSourceLicense($resourceDao->getSourceLicense());
          $resourceDao->setAgreedAttributionPolicy($resourceDao->getAgreedAttributionPolicy());
          if ($resourceDao->getHasCode() == "true")
            {
            $resourceDao->setHasCode();
            }<commit_msg>Remove pre-population of uploads on new revision<commit_after><?php
/*=========================================================================
 *
 *  Copyright OSHERA Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

class Journal_SubmitController extends Journal_AppController
{
  function init()
    {

    }

  /** The first step of the submission process is to select an issue */
  function selectissueAction()
    {
    if(!$this->logged)
      {
      $this->renderScript("login.phtml");
      return;
      }
    $this->view->issues = MidasLoader::loadModel("Issue", 'journal')->findActiveIssues();
    foreach($this->view->issues as $key => $issue)
      {
      $community = MidasLoader::loadModel("Folder")->getCommunity(MidasLoader::loadModel("Folder")->getRoot($issue));
      if(isset($_GET['community']) && $community->getKey() !=  $_GET['community']) unset($this->view->issues[$key]);
      if(!$community || !MidasLoader::loadModel("Community")->policyCheck($community, $this->userSession->Dao))
        {
        unset($this->view->issues[$key]);
        }
      }
    }

  /** Form allowing the user to submit an article*/
  function indexAction()
    {
    if(!$this->logged)
      {
      $this->renderScript("login.phtml");
      return;
      }
    // load resource if it exists
    $item_id = $this->_getParam('itemId');
    $revision_id = $this->_getParam('revisionId');
    $issueId = $this->_getParam('issue');
    $isNewSubmission = false;

    // New Revision
    if(isset($item_id))
      {
      $item = MidasLoader::loadModel("Item")->load($item_id);
      if(!MidasLoader::loadModel("Item")->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_WRITE))
        {
        throw new Zend_Exception("Permissions error.");
        }
      $resourceDao = MidasLoader::loadModel("Item")->initDao("Resource", $item->toArray(), "journal");
      $resourceDao->setRevision("New");
      $folder = end($item->getFolders());
      $this->view->json['showlicence'] = 1;
      }
    // Edit
    else if(isset($revision_id))
      {
      $revision = MidasLoader::loadModel("ItemRevision")->load($revision_id);
      if(!$revision)
        {
        throw new Zend_Exception("Unable to find revision.");
        }
      $item = $revision->getItem();
      $resourceDao = MidasLoader::loadModel("Item")->initDao("Resource", $item->toArray(), "journal");
      $resourceDao->setRevision($revision);
      if(!MidasLoader::loadModel("Item")->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_WRITE) )
        {
        throw new Zend_Exception("Permissions error.");
        }
      $folder = end($item->getFolders());
      $this->view->json['showlicence'] = 0;
      }
    // New Resource
    else
      {
      $resourceDao = MidasLoader::newDao('ResourceDao', 'journal');
      $resourceDao->setRevision("New");
      $isNewSubmission = true;
      $folder = MidasLoader::loadModel("Folder")->load($issueId);
      if(!$folder)throw new Zend_Exception("Unable to find issue.");
      $this->view->json['showlicence'] = 1;
      }

    $this->view->issueDao = MidasLoader::loadModel("Folder")->initDao("Issue", $folder->toArray(), "journal");

    // Process form result
    if($this->_request->isPost())
      {
      $resourceDao->setName($_POST['title']);
      $resourceDao->setDescription($_POST['description']);
      $resourceDao->setType($_POST['type']);
      $resourceDao->setThumbnailId(new Zend_Db_Expr('NULL'));
      $anonymousGroup = MidasLoader::loadModel("Group")->load(MIDAS_GROUP_ANONYMOUS_KEY);
      $isNew = !$resourceDao->saved;
      // Create or update resource
      MidasLoader::loadModel("Item")->save($resourceDao);
      $itemRevisionDao = $resourceDao->getRevision();

      // create a new revision
      if(!$itemRevisionDao->saved)
        {
        $itemRevisionDao->setChanges("");
        $itemRevisionDao->setUser_id($this->userSession->Dao->getKey());
        $itemRevisionDao->setDate(date('c'));
        $itemRevisionDao->setLicenseId(null);
        $lastExistingRevision = MidasLoader::loadModel("Item")->getLastRevision($resourceDao);
        MidasLoader::loadModel("Item")->addRevision($resourceDao, $itemRevisionDao);
        if($lastExistingRevision) // If new revision, copy previous data
          {
          // Need to copy anything that's not updated on this view
          $resourceDao->setHandle($resourceDao->getHandle());
          $resourceDao->setSourceLicense($resourceDao->getSourceLicense());
          $resourceDao->setAgreedAttributionPolicy($resourceDao->getAgreedAttributionPolicy());
          if ($resourceDao->getHasCode() == "true")
            {
            $resourceDao->setHasCode();
            }
{'fraction_non_alphanumeric': 0.1814480439015755, 'fraction_numerical': 0.0012391573729863693, 'mean_word_length': 3.3794573643410852, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 173, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2468397', 'n_tokens_mistral': 3262, 'n_tokens_neox': 3250, 'n_words': 587}