Skip to content

Commit 96366e4

Browse files
authored
Merge pull request #28 from uWaterloo/22-core_version_requirement
Write core key only if no core_version_requirement, fixes #22
2 parents 393027f + 127be78 commit 96366e4

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Writer/Drupal.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ class Drupal implements WriterInterface
1212
*/
1313
const VERSION_EXISTS_PATTERN = '#version:.*[\d+].*#';
1414

15+
/**
16+
* Pattern to indicate a file has core_version_requirement.
17+
*/
18+
const CORE_VERSION_REQUIREMENT_EXISTS_PATTERN = '#core_version_requirement:.*#';
19+
1520
/**
1621
* File paths to rewrite.
1722
*
@@ -36,7 +41,8 @@ public function rewrite($version, $timestamp, $core = null, $project = null)
3641
// Don't write to files that already contain version information.
3742
if (!$this->hasVersionInfo($info_file)) {
3843
$file = fopen($info_file, 'a+');
39-
fwrite($file, $this->formatInfo($version, $timestamp, $core, $project));
44+
$coreToWrite = $this->hasCoreVersionRequirement($info_file) ? null : $core;
45+
fwrite($file, $this->formatInfo($version, $timestamp, $coreToWrite, $project));
4046
fclose($file);
4147
}
4248
}
@@ -93,4 +99,19 @@ protected function hasVersionInfo($file_path)
9399
$contents = file_get_contents($file_path);
94100
return preg_match(static::VERSION_EXISTS_PATTERN, $contents);
95101
}
102+
103+
/**
104+
* Determine if a given file contains core_version_requirement.
105+
*
106+
* @param string $file_path
107+
* Path to the info file.
108+
*
109+
* @return bool
110+
* Returns true if file already has core_version_requirement.
111+
*/
112+
protected function hasCoreVersionRequirement($file_path)
113+
{
114+
$contents = file_get_contents($file_path);
115+
return preg_match(static::CORE_VERSION_REQUIREMENT_EXISTS_PATTERN, $contents);
116+
}
96117
}

0 commit comments

Comments
 (0)