有一些類似的問題,但他們都沒有幫助我的案例。所有其他問題都在討論版本號,但我需要的只是增加內部版本號。如何在PHP中自動增加內部版本號
我需要一個腳本,將檢查是否有任何改變的文件/創建/刪除,並以1
增加版本號我找不到的答案,這個問題在網上和編寫了一個腳本自己。我在問這個問題,所以我可以分享我的腳本作爲答案。
這是我想出的腳本。隨意進一步改進和修改我的答案或張貼自己的答案:
// Opening the json file that holds the file paths and file modification dates
$jsonArray = json_decode(file_get_contents('files.json'), true);
$jsonFileArray = array();
// Putting the values into a local array
foreach ($jsonArray as $filePath => $modifiedDate) {
$jsonFileArray[$filePath] = $modifiedDate;
}
// Iterating through the directories and putting the file paths and modification dates into a local array
$filesArray = array();
$dir_iterator = new RecursiveDirectoryIterator(".");
$recursive_iterator = new RecursiveIteratorIterator($dir_iterator);
foreach ($recursive_iterator as $file) {
if ($file->isDir()) {
continue;
}
if (substr($file, -9) != 'error_log') {
$fileName = $file->getPathname();
$fileModifiedDate = date('m/d/y H:i:s', $file->getMTime());
$filesArray[$fileName] = $fileModifiedDate;
}
}
// Checking if there are any files that are modified/created/deleted
if ($jsonFileArray != $filesArray) {
// If there are any changes, the build number is increased by 1 and saved into 'build' file
$buildFile = "build";
file_put_contents($buildFile, file_get_contents($buildFile) + 1);
}
// Updating the json file with the latest modifiedDates
$jsonFile = fopen('files.json', 'w');
fwrite($jsonFile, json_encode($filesArray, JSON_UNESCAPED_SLASHES));
fclose($jsonFile);
哇,這是一個快速downvote(2秒內)。我認爲你甚至不可能在2秒內閱讀這個問題。 –
我相信你被低估了,因爲你的問題沒有表現出什麼努力,而且非常寬泛。你也有幾個密切的選票,這兩個都表明你的問題太廣泛了。 –
遞減投票是好的,我不反對這一點。但是,即使沒有閱讀這個問題,但是下調是荒謬的。他/她應該增加評論,所以我可以改善這個問題。我在問題中添加了我的代碼,並試圖在文本中進一步闡明它。我試圖讓這是一個質量問題,但降價並不是很有幫助。如果你想改進它,請添加評論或自己編輯問題。 –