/**
  * Récupère les notices marquées comme supprimées de tout les sets
  * @param array $notice_sets Tableau des identifiants de sets
  * @param array $records_not_deleted Tableau des identifiants de notices présentes dans au moins un set
  * @param iso8601 $iso8601
  *
  * @return array Renvoie un tableau array({id_notice} => array('datestamp', 'sets'))
  */
 private function get_deleted_records($record_sets, $records_not_deleted, $iso8601)
 {
     global $dbh;
     $deleted_records = array();
     $query = "select num_notice, num_set, unix_timestamp(deletion_date) as datestamp from connectors_out_oai_deleted_records where num_set in (" . implode(",", $record_sets) . ") and num_notice not in (" . implode(",", $records_not_deleted) . ")";
     if ($this->deletion_management == 1) {
         $query .= " and timestampdiff(second, deletion_date, now()) < " . $this->deletion_management_transient_duration;
     }
     $result = pmb_mysql_query($query, $dbh);
     if ($result && pmb_mysql_num_rows($result)) {
         while ($row = mysql_fetch_object($result)) {
             $deleted_records[$row->num_notice]['sets'][] = $row->num_set;
             $timestamp = $iso8601->unixtime_to_iso8601($row->datestamp);
             if (!isset($deleted_records[$row->num_notice]['datestamp']) || $timestamp > $deleted_records[$row->num_notice]['datestamp']) {
                 $deleted_records[$row->num_notice]['datestamp'] = $timestamp;
             }
         }
     }
     foreach ($deleted_records as $record_id => $record) {
         // Si la notice n'est pas supprimée de tous les sets
         if (count($not_deleted_sets = connector_out_set_noticecaddie::get_notice_setlist($record_id))) {
             // Si la notice n'est pas supprimée de tous les sets de la source, on l'enlève des notices supprimées
             if (count(array_intersect($not_deleted_sets, $record_sets))) {
                 unset($deleted_records[$record_id]);
             }
         }
     }
     return $deleted_records;
 }
示例#2
0
    function convert_batch_to_oairecords($notices_to_convert, $format, $target_charset)
    {
        global $dbh;
        if (!$notices_to_convert) {
            //Rien à faire? On fait rien
            return;
        }
        //Allons chercher les dates et les statuts des notices
        $notice_datestamps = array();
        $notice_statuts = array();
        $notice_ids = $notices_to_convert;
        //Par paquets de 100 pour ne pas brusquer mysql
        $notice_idsz = array_chunk($notice_ids, 100);
        $iso8601 = new iso8601("YYYY-MM-DDThh:mm:ssZ");
        foreach ($notice_idsz as $anotice_ids) {
            $sql = "SELECT notice_id, UNIX_TIMESTAMP(update_date) AS datestamp, statut FROM notices WHERE notice_id IN (" . implode(",", $anotice_ids) . ")";
            $res = mysql_query($sql, $dbh);
            while ($row = mysql_fetch_assoc($res)) {
                $notice_datestamps[$row["notice_id"]] = $iso8601->unixtime_to_iso8601($row["datestamp"]);
                $notice_statuts[$row["notice_id"]] = $row["statut"];
            }
        }
        //Si il existe un status correspondant à la suppression, on génère ces enregistrements et on les supprime de la liste à générer.
        if ($this->deleted_record_statut) {
            foreach ($notice_statuts as $notice_id => $anotice_statut) {
                if ($anotice_statut == $this->deleted_record_statut) {
                    $notice_sets = connector_out_set_noticecaddie::get_notice_setlist($notice_id);
                    $notice_sets = array_intersect($notice_sets, $this->source_set_ids);
                    $oai_record = "";
                    $oai_record .= "<record>";
                    $oai_record .= '<header status="deleted">
									<identifier>oai:' . XMLEntities($this->repository_identifier) . ':' . $notice_id . '</identifier>
									<datestamp>' . $notice_datestamps[$notice_id] . '</datestamp>';
                    foreach ($notice_sets as $aset_id) {
                        $oai_record .= "<setSpec>set_" . $aset_id . "</setSpec>";
                    }
                    $oai_record .= '</header>';
                    $oai_record .= "</record>";
                    $this->results[$notice_id] = $oai_record;
                    unset($notices_to_convert[array_search($notice_id, $notices_to_convert)]);
                }
            }
        }
        //Convertissons les notices au format demandé si on ne souhaite pas uniquement les entêtes
        $only_identifier = $format == "__oai_identifier";
        if (!$only_identifier) {
            $converter = new external_services_converter_notices(1, $this->set_life_duration);
            $converter->params["include_items"] = $this->include_items;
            $converter->params["include_links"] = $this->include_links;
            $metadatas = $converter->convert_batch($notices_to_convert, $format, $target_charset, $this->xslt);
        }
        //Fabriquons les enregistrements
        foreach ($notices_to_convert as $notice_id) {
            $notice_sets = connector_out_set_noticecaddie::get_notice_setlist($notice_id);
            $notice_sets = array_intersect($notice_sets, $this->source_set_ids);
            $oai_record = "";
            if (!$only_identifier) {
                $oai_record .= "<record>";
            }
            $oai_record .= '<header>
							<identifier>oai:' . XMLEntities($this->repository_identifier) . ':' . $notice_id . '</identifier>
							<datestamp>' . $notice_datestamps[$notice_id] . '</datestamp>';
            foreach ($notice_sets as $aset_id) {
                $oai_record .= "<setSpec>set_" . $aset_id . "</setSpec>";
            }
            $oai_record .= '</header>';
            if (!$only_identifier) {
                $oai_record .= "<metadata>";
                $oai_record .= $metadatas[$notice_id];
                $oai_record .= "</metadata>";
            }
            if (!$only_identifier) {
                $oai_record .= "</record>";
            }
            $this->results[$notice_id] = $oai_record;
        }
    }