Skip to content
Snippets Groups Projects
Commit 3c2634c7 authored by Demian Katz's avatar Demian Katz
Browse files

More function simplification, plus addition of test.

parent e1fd36be
No related merge requests found
......@@ -774,6 +774,26 @@ class Upgrade
$this->saveModifiedConfig('WorldCat.ini');
}
/**
* Does the specified properties file contain any meaningful
* (non-empty/non-comment) lines?
*
* @param string $src File to check
*
* @return bool
*/
protected function fileContainsMeaningfulLines($src)
{
// Does the file contain any meaningful lines?
foreach (file($src) as $line) {
$line = trim($line);
if (!empty($line) && substr($line, 0, 1) != '#') {
return true;
}
}
return false;
}
/**
* Upgrade SolrMarc configurations.
*
......@@ -792,19 +812,8 @@ class Upgrade
return;
}
// Does the file contain any meaningful lines?
$lines = file($src);
$empty = true;
foreach ($lines as $line) {
$line = trim($line);
if (!empty($line) && substr($line, 0, 1) != '#') {
$empty = false;
break;
}
}
// Copy the file if it contains customizations:
if (!$empty) {
if ($this->fileContainsMeaningfulLines($src)) {
$dest = realpath($this->newDir . '/../../import')
. '/marc_local.properties';
if (!copy($src, $dest) || !file_exists($dest)) {
......
# this file contains no meaningful lines
# this is junk
# this file contains a meaningful line
key = "value"
\ No newline at end of file
......@@ -176,4 +176,30 @@ class UpgradeTest extends \VuFindTest\Unit\TestCase
'Custom Generator', $results['config.ini']['Site']['generator']
);
}
/**
* Test "meaningful line" detection in SolrMarc properties files.
*
* @return void
*/
public function testMeaningfulLineDetection()
{
$upgrader = $this->getUpgrader('1.4');
$meaningless = realpath(
__DIR__ . '/../../../../fixtures/configs/solrmarc/empty.properties'
);
$this->assertFalse(
$this->callMethod(
$upgrader, 'fileContainsMeaningfulLines', array($meaningless)
)
);
$meaningful = realpath(
__DIR__ . '/../../../../fixtures/configs/solrmarc/meaningful.properties'
);
$this->assertTrue(
$this->callMethod(
$upgrader, 'fileContainsMeaningfulLines', array($meaningful)
)
);
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment