Пример #1
0
 /**
  * Export records from AMS for PBCore and PREMIS and save all the exported records in zip file using BagIt.
  * 
  * @return void
  */
 function export_pbcore()
 {
     @ini_set("max_execution_time", 999999999999.0);
     # unlimited
     @ini_set("memory_limit", "2000M");
     # 2GB
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     $export_job = $this->export_job->get_export_jobs('pbcore');
     if (count($export_job) > 0) {
         $this->export_job->update_job($export_job->id, array('status' => '1'));
         myLog('Started export for ID =>' . $export_job->id);
         $bag_name = 'ams_export_' . time();
         $bagit_info = array('Source-Organization' => 'WGBH on behalf of the American Archive of Public Broadcasting', 'Organization-Address' => 'Media Library & Archives, One Guest Street, Boston, MA 02135', 'Contact-Name' => 'Casey E. Davis, Project Manager', 'Contact-Phone' => '+1 617-300-5921', 'Contact-Email' => 'info@americanarchive.org ', 'External-Description' => 'The American Archive of Public Broadcasting, a collaboration between WGBH Boston and the Library of Congress, includes millions of records of public television and radio assets contributed by over 100 stations and organizations across the United States.');
         $bagit_lib = new BagIt("{$this->bagit_path}{$bag_name}", TRUE, TRUE, FALSE, $bagit_info);
         $bagit_lib->setHashEncoding('md5');
         $total_size = 0;
         $total_files = 0;
         if ($export_job->query_loop == 0) {
             $export_ids = explode(',', $export_job->export_query);
             foreach ($export_ids as $asset_id) {
                 $this->do_export($asset_id, $total_size, $total_files, $bagit_lib);
             }
         } else {
             for ($i = 0; $i < $export_job->query_loop; $i++) {
                 $query = $export_job->export_query;
                 $query .= ' LIMIT ' . $i * 100000 . ', 100000';
                 $records = $this->export_job->get_csv_records($query);
                 foreach ($records as $value) {
                     $this->do_export($value->id, $total_size, $total_files, $bagit_lib);
                 }
             }
         }
         $bagit_lib->setBagInfoData('Payload-Oxum', $total_size . '.' . $total_files);
         $bagit_lib->setBagInfoData('Bagging-Date', date('Y-m-d'));
         $bagit_lib->setBagInfoData('Bag-Size', sizeFormat($total_size));
         $bagit_lib->update();
         $bagit_lib->package("{$this->bagit_path}{$bag_name}", 'zip');
         exec("rm -rf {$this->temp_path}");
         exec("rm -rf {$this->bagit_path}{$bag_name}");
         $this->export_job->update_job($export_job->id, array('status' => '1', 'file_path' => "{$this->bagit_path}{$bag_name}.zip"));
         $user = $this->users->get_user_by_id($export_job->user_id)->row();
         $data['user_profile'] = $this->user_profile->get_profile($export_job->user_id)->row();
         $data['user'] = $user;
         $data['export_id'] = $export_job->id;
         myLog('Sending Email to ' . $user->email);
         send_email($user->email, $this->config->item('from_email'), 'AMS XML Export', $this->load->view('email/export_pbcore', $data, TRUE));
         myLog('email sent successfully ' . $user->email);
     } else {
         myLog('No record availabe for export');
     }
     exit_function();
 }
Пример #2
0
 public function testPackageTGz()
 {
     $tmp = tmpdir();
     try {
         mkdir($tmp);
         mkdir($tmp . '/data');
         file_put_contents($tmp . '/data/missing.txt', 'This space intentionally left blank.\\n');
         file_put_contents($tmp . "/fetch.txt", "http://www.google.com - data/google/index.html\n" . "http://www.yahoo.com - data/yahoo/index.html\n");
         $bag = new BagIt($tmp);
         $bag->update();
         $bag->package($tmp . '/../bagtmp1.tgz', 'tgz');
         $this->assertFileExists($tmp . '/../bagtmp1.tgz');
         rename("{$tmp}/../bagtmp1.tgz", "/tmp/bagtmp1.tgz");
         $bag->package($tmp . '/../bagtmp2', 'tgz');
         $this->assertFileExists($tmp . '/../bagtmp2.tgz');
         rename("{$tmp}/../bagtmp2.tgz", "/tmp/bagtmp2.tgz");
         // TODO: Test the contents of the package.
     } catch (Exception $e) {
         rrmdir($tmp);
         throw $e;
     }
     rrmdir($tmp);
 }
Пример #3
0
/**
 * Read the Bag, unpack it, drop files into the Dropbox files directory.
 *
 * @param string $filename The name of the uploaded bag.
 *
 * @return boolean $success True if the read succeeds.
 */
function bagithelpers_doReadBagIt($filename)
{
    $success = false;
    $bag = new BagIt(BAGIT_TMP_DIRECTORY . '/' . $filename);
    $bag->fetch->download();
    $bag->update();
    $bag->validate();
    if (count($bag->getBagErrors()) == 0) {
        // Copy each of the files.
        foreach ($bag->getBagContents() as $file) {
            copy($file, BASE_DIR . '/plugins/Dropbox/files/' . basename($file));
        }
        $success = true;
    }
    return $success;
}
Пример #4
0
 /**
  * Create a package containing the serialized deposit objects 
  * @return string The full path of the created zip archive
  */
 function generatePackage()
 {
     // get DAOs, plugins and settings
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     $issueDao =& DAORegistry::getDAO('IssueDAO');
     $sectionDao =& DAORegistry::getDAO('SectionDAO');
     $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
     PluginRegistry::loadCategory('importexport');
     $exportPlugin =& PluginRegistry::getPlugin('importexport', 'NativeImportExportPlugin');
     $plnPlugin =& PluginRegistry::getPlugin('generic', PLN_PLUGIN_NAME);
     $fileManager = new JournalFileManager($journalDao->getById($this->_deposit->getJournalId()));
     $journal =& $journalDao->getById($this->_deposit->getJournalId());
     $depositObjects = $this->_deposit->getDepositObjects();
     // set up folder and file locations
     $bagDir = $this->getDepositDir() . DIRECTORY_SEPARATOR . 'bag';
     $packageFile = $this->getPackageFilePath();
     $exportFile = $bagDir . DIRECTORY_SEPARATOR . $this->_deposit->getObjectType() . '.xml';
     $termsFile = $bagDir . DIRECTORY_SEPARATOR . 'terms.xml';
     $bag = new BagIt($bagDir);
     switch ($this->_deposit->getObjectType()) {
         case PLN_PLUGIN_DEPOSIT_OBJECT_ARTICLE:
             $articles = array();
             // we need to add all of the relevant articles to an array to export as a batch
             while ($depositObject =& $depositObjects->next()) {
                 $article =& $publishedArticleDao->getPublishedArticleByArticleId($this->_deposit->getObjectId(), $journal->getId());
                 $issue =& $issueDao->getIssueById($article->getIssueId(), $journal->getId());
                 $section =& $sectionDao->getSection($article->getSectionId());
                 // add the article to the array we'll pass for export
                 $articles[] = array('publishedArticle' => $article, 'section' => $section, 'issue' => $issue, 'journal' => $journal);
                 unset($depositObject);
             }
             // export all of the articles together
             if ($exportPlugin->exportArticles($articles, $exportFile) !== true) {
                 return false;
             }
             break;
         case PLN_PLUGIN_DEPOSIT_OBJECT_ISSUE:
             // we only ever do one issue at a time, so get that issue
             $depositObject =& $depositObjects->next();
             $issue =& $issueDao->getIssueByBestIssueId($depositObject->getObjectId(), $journal->getId());
             // export the issue
             if ($exportPlugin->exportIssue($journal, $issue, $exportFile) !== true) {
                 return false;
             }
             break;
         default:
     }
     // add the current terms to the bag
     $termsXml = new DOMDocument('1.0', 'utf-8');
     $entry = $termsXml->createElementNS('http://www.w3.org/2005/Atom', 'entry');
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:dcterms', 'http://purl.org/dc/terms/');
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:pkp', PLN_PLUGIN_NAME);
     $terms = unserialize($plnPlugin->getSetting($this->_deposit->getJournalId(), 'terms_of_use'));
     $pkpTermsOfUse = $termsXml->createElementNS(PLN_PLUGIN_NAME, 'pkp:terms_of_use');
     foreach ($terms as $termName => $termData) {
         $element = $termsXml->createElementNS(PLN_PLUGIN_NAME, $termName, $termData['term']);
         $element->setAttribute('updated', $termData['updated']);
         $pkpTermsOfUse->appendChild($element);
     }
     $entry->appendChild($pkpTermsOfUse);
     $termsXml->appendChild($entry);
     $termsXml->save($termsFile);
     // add the exported content to the bag
     $bag->addFile($exportFile, $this->_deposit->getObjectType() . $this->_deposit->getUUID() . '.xml');
     // add the exported content to the bag
     $bag->addFile($termsFile, 'terms' . $this->_deposit->getUUID() . '.xml');
     $bag->update();
     // delete files
     $fileManager->deleteFile($exportFile);
     $fileManager->deleteFile($termsFile);
     // create the bag
     $bag->package($packageFile, 'zip');
     // remove the temporary bag directory
     $fileManager->rmtree($bagDir);
     return $packageFile;
 }
Пример #5
0
 /**
  * This is the use case for consuming a bag from someone else. The user 
  * does these actions:
  *
  * <ol>
  * <li>Open the bag;</li>
  * <li>Validate the downloaded contents;</li>
  * <li>Fetch on-line items in the bag;</li>
  * <li>Validate the bag's contents; and</li>
  * <li>Copy items from the bag onto the local disk.</li>
  * </ol>
  */
 public function testBagConsumer()
 {
     $srcbag = __DIR__ . '/TestBag.tgz';
     // 1. Open the bag;
     $bag = new BagIt($srcbag);
     $this->queueRm($bag->bagDirectory);
     $this->assertTrue($bag->isValid());
     $this->assertTrue($bag->isExtended());
     $bagInfo = $bag->getBagInfo();
     $this->assertEquals('0.96', $bagInfo['version']);
     $this->assertEquals('UTF-8', $bagInfo['encoding']);
     $this->assertEquals('sha1', $bagInfo['hash']);
     $this->assertEquals('sha1', $bag->getHashEncoding());
     $this->assertEquals(7, count($bag->getBagContents()));
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 2. Validate the downloaded contents;
     $bag->validate();
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 3. Fetch on-line items in the bag;
     $bag->fetch->download();
     $bag->update();
     $bag->validate();
     $this->assertEquals(8, count($bag->getBagContents()));
     // 4. Validate the bag's contents; and
     $this->assertEquals(0, count($bag->getBagErrors()));
     // 5. Copy items from the bag onto the local disk.
     $tmpdir = tmpdir();
     mkdir($tmpdir);
     $this->queueRm($tmpdir);
     foreach ($bag->getBagContents() as $bagFile) {
         $basename = basename($bagFile);
         copy($bagFile, "{$tmpdir}/{$basename}");
     }
     $this->assertEquals(count($bag->getBagContents()) + 2, count(scandir($tmpdir)));
     $this->assertEquals(count($bag->manifest->getData()) + 2, count(scandir($tmpdir)));
 }
Пример #6
0
 public function testNewBagEmpty()
 {
     $bagdir = "{$this->tmpdir}/_bag";
     $bag = new BagIt($bagdir);
     $this->assertFileNotExists("{$bagdir}/fetch.txt");
     $bag->update();
     $this->assertFileNotExists("{$bagdir}/fetch.txt");
 }