/**
 *
 * Dieses Skript findet alle Dokumente mit ServerState=published, deren ServerDateModified im Solr-Index kleiner ist
 * als das Datum in der Datenbank. Ist ein Dokument nicht im Index vorhanden, wird eine entsprechende
 * Fehlermeldung pro Dokument ausgegeben.
 *
 * Siehe dazu auch das Ticket OPUSVIER-2853.
 *
 */
$numOfModified = 0;
$numOfErrors = 0;
$finder = new Opus_DocumentFinder();
$finder->setServerState('published');
foreach ($finder->ids() as $docId) {
    // check if document with id $docId is already persisted in search index
    $search = Opus_Search_Service::selectSearchingService();
    $query = Opus_Search_QueryFactory::selectDocumentById($search, $docId);
    if ($search->customSearch($query)->getAllMatchesCount() != 1) {
        echo "ERROR: document # {$docId} is not stored in search index\n";
        $numOfErrors++;
    } else {
        $result = $search->getResults();
        $solrModificationDate = $result[0]->getServerDateModified();
        $document = new Opus_Document($docId);
        $docModificationDate = $document->getServerDateModified()->getUnixTimestamp();
        if ($solrModificationDate != $docModificationDate) {
            $numOfModified++;
            echo "document # {$docId} is modified\n";
        }
    }
}