Created
January 17, 2019 15:09
-
-
Save Opencontent/93ba996a98cc24639041c1bf289e2c89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = '/Users/luca/git/AWS/solr-consorzioweb/java/solr'; | |
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); | |
foreach ($objects as $entry){ | |
if ($entry->getFilename() == "schema.xml" ){ | |
chdir($entry->getPath()); | |
$path = $entry->getPath() . "/schema.xml"; | |
$content = file_get_contents($path); | |
echo "controllo " . $path . "\n"; | |
$doc = DOMDocument::loadXML($content); | |
$xpath = new DOMXpath($doc); | |
$elements = $xpath->query("//field[@name = 'ezf_df_tags']"); | |
if ($elements->length == 0){ | |
$fields = $xpath->query("//fields"); | |
foreach ($fields as $field) { | |
if($field->getNodePath() == '/schema/fields'){ | |
//<field name="ezf_df_tags" type="lckeyword" indexed="true" stored="true" multiValued="true" termVectors="true"/> | |
$fieldTags = $doc->createElement("field"); | |
$fieldTags->setAttribute('name', 'ezf_df_tags'); | |
$fieldTags->setAttribute('type', 'lckeyword'); | |
$fieldTags->setAttribute('indexed', 'true'); | |
$fieldTags->setAttribute('stored', 'true'); | |
$fieldTags->setAttribute('multiValued', 'true'); | |
$fieldTags->setAttribute('termVectors', 'termVectors'); | |
$field->appendChild($fieldTags); | |
//<field name="ezf_df_tag_ids" type="sint" indexed="true" stored="true" multiValued="true" termVectors="true"/> | |
$fieldTagsIds = $doc->createElement("field"); | |
$fieldTagsIds->setAttribute('name', 'ezf_df_tag_ids'); | |
$fieldTagsIds->setAttribute('type', 'sint'); | |
$fieldTagsIds->setAttribute('indexed', 'true'); | |
$fieldTagsIds->setAttribute('stored', 'true'); | |
$fieldTagsIds->setAttribute('multiValued', 'true'); | |
$fieldTagsIds->setAttribute('termVectors', 'termVectors'); | |
$field->appendChild($fieldTagsIds); | |
$newContent = $doc->saveXML(); | |
if (!file_put_contents($path, $newContent)){ | |
echo "Errore salvando il file \n"; | |
}else{ | |
echo "Modifico il file\n"; | |
} | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment