public static function syncGitChapter2Bible($git, $bible, $book, $chapter) { // The databases. $database_bibles = Database_Bibles::getInstance(); $database_books = Database_Books::getInstance(); $database_logs = Database_Logs::getInstance(); // Filename for the chapter. $bookname = $database_books->getEnglishFromId($book); $filename = "{$git}/{$bookname}/{$chapter}/data"; if (file_exists($filename)) { // Store chapter in database. $usfm = file_get_contents($filename); Bible_Logic::storeChapter($bible, $book, $chapter, $usfm); $database_logs->log(Locale_Translate::_("A collaborator updated") . " {$bible} {$bookname} {$chapter}"); } else { // Delete chapter from database. Bible_Logic::deleteChapter($bible, $book, $chapter); $database_logs->log(Locale_Translate::_("A collaborator deleted chapter") . " {$bible} {$bookname} {$chapter}"); } }
} } // Clean out nearly empty chapters from the Bibles. $bibles = $database_bibles->getBibles(); foreach ($bibles as $bible) { $books = $database_bibles->getBooks($bible); foreach ($books as $book) { $chapters = $database_bibles->getChapters($bible, $book); foreach ($chapters as $chapter) { // Remove chapters, other than 0, that are rather short, as these chapters likely contain no text, but USFM markers only. if ($chapter == 0) { continue; } $usfm = $database_bibles->getChapter($bible, $book, $chapter); $length = strlen($usfm); if ($length < 1000) { Bible_Logic::deleteChapter($bible, $book, $chapter); } } // If a book contains chapter 0 only, remove that entire book. $chapters = $database_bibles->getChapters($bible, $book); if ($chapters == array(0)) { Bible_Logic::deleteBook($bible, $book); } } // If a Bible contains no books, remove that Bible. $books = $database_bibles->getBooks($bible); if (empty($books)) { Bible_Logic::deleteBible($bible); } }