示例#1
0
文件: git.php 项目: alerque/bibledit
 public static function syncGit2Bible($git, $bible)
 {
     $success = true;
     $database_bibles = Database_Bibles::getInstance();
     $database_books = Database_Books::getInstance();
     $database_logs = Database_Logs::getInstance();
     // Stage one:
     // Read the chapters in the git repository,
     // and check that they occur in the database.
     // If any does not occur, add the chapter to the database.
     // This stage does not check the contents of the chapters.
     $books = $database_bibles->getBooks($bible);
     foreach (new DirectoryIterator($git) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         if ($fileInfo->isDir()) {
             $bookname = $fileInfo->getFilename();
             $book = $database_books->getIdFromEnglish($bookname);
             if ($book) {
                 // Check the chapters.
                 $chapters = $database_bibles->getChapters($bible, $book);
                 foreach (new DirectoryIterator("{$git}/{$bookname}") as $fileInfo2) {
                     if ($fileInfo2->isDot()) {
                         continue;
                     }
                     if ($fileInfo2->isDir()) {
                         $chapter = $fileInfo2->getFilename();
                         if (is_numeric($chapter)) {
                             $filename = "{$git}/{$bookname}/{$chapter}/data";
                             if (file_exists($filename)) {
                                 if (!in_array($chapter, $chapters)) {
                                     // Chapter does not exist in the database: Add it.
                                     $usfm = file_get_contents($filename);
                                     Bible_Logic::storeChapter($bible, $book, $chapter, $usfm);
                                     $database_logs->log(Locale_Translate::_("A translator added chapter") . " {$bible} {$bookname} {$chapter}");
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Stage two:
     // Read through the chapters in the database,
     // and check that they occur in the git folder.
     // If necessary, remove a chapter from the database.
     // If a chapter matches, check that the contents of the data in the git
     // folder and the contents in the database match.
     // If necessary, update the data in the database.
     $books = $database_bibles->getBooks($bible);
     foreach ($books as $book) {
         $bookname = $database_books->getEnglishFromId($book);
         $bookdir = "{$git}/{$bookname}";
         if (file_exists($bookdir)) {
             $chapters = $database_bibles->getChapters($bible, $book);
             foreach ($chapters as $chapter) {
                 $chapterdir = "{$bookdir}/{$chapter}";
                 if (file_exists($chapterdir)) {
                     $datafile = "{$chapterdir}/data";
                     $contents = file_get_contents($datafile);
                     $usfm = $database_bibles->getChapter($bible, $book, $chapter);
                     if ($contents != $usfm) {
                         Bible_Logic::storeChapter($bible, $book, $chapter, $contents);
                         $database_logs->log(Locale_Translate::_("A translator updated chapter") . " {$bible} {$bookname} {$chapter}");
                     }
                 } else {
                     Bible_Logic::deleteChapter($bible, $book, $chapter);
                     $database_logs->log(Locale_Translate::_("A translator deleted chapter") . " {$bible} {$bookname} {$chapter}");
                 }
             }
         } else {
             Bible_Logic::deleteBook($bible, $book);
             $database_logs->log(Locale_Translate::_("A translator deleted book") . " {$bible} {$bookname}");
         }
     }
 }
示例#2
0
        $dialog_books = new Dialog_Books(array("bible"), Locale_Translate::_("Create book"), "", "", "createbook", NULL, $database_bibles->getBooks($bible));
        die;
    } else {
        $feedback = array();
        if ($write_access) {
            Book_Create::create($bible, $createbook, NULL, $feedback);
        }
    }
}
// Book deletion.
@($deletebook = $_GET['deletebook']);
if ($deletebook != "") {
    @($confirm = $_GET['confirm']);
    if ($confirm != "") {
        if ($write_access) {
            Bible_Logic::deleteBook($bible, $deletebook);
        }
    } else {
        $dialog_yes = new Dialog_Yes(array("bible"), Locale_Translate::_("Would you like to delete this book?"), "deletebook");
        die;
    }
}
// Available books.
$book_names = array();
$book_ids = Filter_Books::getOrdered($bible);
foreach ($book_ids as $book) {
    $book_name = $database_books->getEnglishFromId($book);
    $book_name = Locale_Translate::_($book_name);
    $book_names[] = $book_name;
}
$view->view->book_ids = $book_ids;