Esempio n. 1
0
// Store the verse USFM in the array.
$usfmArray[$verse] = $usfm;
// Create the updated chapter USFM as a string.
$usfm = implode("\n", $usfmArray);
$stylesheet = $database_config_user->getStylesheet();
$book_chapter_text = Filter_Usfm::import($usfm, $stylesheet);
foreach ($book_chapter_text as $data) {
    $book_number = $data[0];
    $chapter_number = $data[1];
    $chapter_data_to_save = $data[2];
    if (($book_number == $book || $book_number == 0) && $chapter_number == $chapter) {
        // Collect some data about the changes for this user.
        $username = $session_logic->currentUser();
        $oldID = $database_bibles->getChapterId($bible, $book, $chapter);
        $oldText = $database_bibles->getChapter($bible, $book, $chapter);
        // Safely store the chapter.
        $saved = Filter_Bibles::safeStoreChapter($bible, $book, $chapter, $chapter_data_to_save);
        if ($saved) {
            // Store details for the user's changes.
            $newID = $database_bibles->getChapterId($bible, $book, $chapter);
            $newText = $chapter_data_to_save;
            $database_modifications->recordUserSave($username, $bible, $book, $chapter, $oldID, $oldText, $newID, $newText);
            echo Locale_Translate::_("Saved");
        } else {
            echo Locale_Translate::_("Not saved because of too many changes");
        }
    } else {
        echo Locale_Translate::_("Save failure");
        $database_logs->log("The following data could not be saved and was discarded: " . $chapter_data_to_save);
    }
}
Esempio n. 2
0
    public function testSafeStoreChapterNoChange()
    {
        $database_bibles = Database_Bibles::getInstance();
        $currentId = $database_bibles->getChapterId("phpunit", 1, 1);
        $usfm = <<<'EOD'
\c 1
\p
\v 1 Verse 1.
\v 2 Verse 2.
\v 3 Verse 3.
\v 4 Verse 4.
\v 5 Verse 5.
EOD;
        $result = Filter_Bibles::safeStoreChapter("phpunit", 1, 1, $usfm);
        $this->assertTrue($result);
        $result = $database_bibles->getChapter("phpunit", 1, 1);
        $this->assertEquals($this->usfm, $result);
        $currentId2 = $database_bibles->getChapterId("phpunit", 1, 1);
        $this->assertEquals($currentId, $currentId2);
    }