コード例 #1
0
ファイル: xml.php プロジェクト: TheHexa1/AMS
 /**
  * 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();
 }