Beispiel #1
0
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Database_Modifications();
     }
     return self::$instance;
 }
Beispiel #2
0
 public function tearDown()
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications = Database_Modifications::getInstance();
     Filter_Client::set(false);
     $database_bibles->deleteBible("phpunit");
     $database_modifications->truncateTeams();
     Filter_Rmdir::rmdir($this->temporary_folder);
 }
Beispiel #3
0
 public function changeNotification($id)
 {
     $database_modifications = Database_Modifications::getInstance();
     $database_logs = Database_Logs::getInstance();
     $passage = $database_modifications->getNotificationPassage($id);
     $passageText = Filter_Books::passagesDisplayInline(array(array($passage['book'], $passage['chapter'], $passage['verse'])));
     $modification = $database_modifications->getNotificationModification($id);
     $session_logic = Session_Logic::getInstance();
     $username = $session_logic->currentUser();
     $database_logs->log("{$username} removed change notification {$passageText}: {$modification}");
 }
Beispiel #4
0
 /**
  * This filter produces files in USFM, html and text format.
  * The text files are to be used for showing the differences between them.
  * The files contain all verses that differ.
  * $bible: The Bible to go through.
  * $directory: The existing directory where to put the files.
  * Two files are created: verses_old.usfm and verses_new.usfm.
  * The book chapter.verse precede each verse.
  */
 public static function produceVerseLevel($bible, $directory)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications = Database_Modifications::getInstance();
     $database_books = Database_Books::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $stylesheet = $database_config_bible->getExportStylesheet($bible);
     $old_vs_usfm = array();
     $new_vs_usfm = array();
     $filter_text_old = new Filter_Text($bible);
     $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
     $filter_text_old->text_text = new Text_Text();
     $filter_text_new = new Filter_Text($bible);
     $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
     $filter_text_new->text_text = new Text_Text();
     $books = $database_modifications->getTeamDiffBooks($bible);
     foreach ($books as $book) {
         $bookname = $database_books->getEnglishFromId($book);
         $chapters = $database_modifications->getTeamDiffChapters($bible, $book);
         foreach ($chapters as $chapter) {
             // Go through the combined verse numbers in the old and new chapter.
             $old_chapter_usfm = $database_modifications->getTeamDiff($bible, $book, $chapter);
             $new_chapter_usfm = $database_bibles->getChapter($bible, $book, $chapter);
             $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm);
             $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm);
             $verses = array_merge($old_verse_numbers, $new_verse_numbers);
             $verses = array_unique($verses);
             sort($verses, SORT_NUMERIC);
             foreach ($verses as $verse) {
                 $old_verse_text = Filter_Usfm::getVerseText($old_chapter_usfm, $verse);
                 $new_verse_text = Filter_Usfm::getVerseText($new_chapter_usfm, $verse);
                 if ($old_verse_text != $new_verse_text) {
                     $usfmCode = "\\p {$bookname} {$chapter}.{$verse} {$old_verse_text}";
                     $old_vs_usfm[] = $usfmCode;
                     $filter_text_old->addUsfmCode($usfmCode);
                     $usfmCode = "\\p {$bookname} {$chapter}.{$verse} {$new_verse_text}";
                     $new_vs_usfm[] = $usfmCode;
                     $filter_text_new->addUsfmCode($usfmCode);
                 }
             }
         }
     }
     file_put_contents("{$directory}/verses_old.usfm", implode("\n", $old_vs_usfm));
     file_put_contents("{$directory}/verses_new.usfm", implode("\n", $new_vs_usfm));
     $filter_text_old->run($stylesheet);
     $filter_text_new->run($stylesheet);
     $filter_text_old->html_text_standard->save("{$directory}/verses_old.html");
     $filter_text_new->html_text_standard->save("{$directory}/verses_new.html");
     $filter_text_old->text_text->save("{$directory}/verses_old.txt");
     $filter_text_new->text_text->save("{$directory}/verses_new.txt");
 }
Beispiel #5
0
 public static function deleteBible($bible)
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications = Database_Modifications::getInstance();
     $database_bibleactions = Database_BibleActions::getInstance();
     // Record data of the Bible to be deleted prior to deletion.
     if (Filter_Client::enabled()) {
         // Client stores Bible actions.
         $books = $database_bibles->getBooks($bible);
         foreach ($books as $book) {
             $chapters = $database_bibles->getChapters($bible, $book);
             foreach ($chapters as $chapter) {
                 $usfm = $database_bibles->getChapter($bible, $book, $chapter);
                 $database_bibleactions->record($bible, $book, $chapter, $usfm);
             }
         }
     } else {
         // Server stores diff data.
         $database_modifications->storeTeamDiffBible($bible);
     }
     // Delete the Bible from the database.
     $database_bibles->deleteBible($bible);
 }
Beispiel #6
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
page_access_level(Filter_Roles::TRANSLATOR_LEVEL);
$database_config_user = Database_Config_User::getInstance();
$database_logs = Database_Logs::getInstance();
$database_bibles = Database_Bibles::getInstance();
$database_modifications = Database_Modifications::getInstance();
$session_logic = Session_Logic::getInstance();
$bible = $_POST['bible'];
$book = $_POST['book'];
$chapter = $_POST['chapter'];
$verse = $_POST['verse'];
$usfm = $_POST['usfm'];
$checksum = $_POST['checksum'];
// Check on information about where to save the verse.
$save = isset($bible) && isset($book) && isset($chapter) && isset($verse) && isset($usfm);
if (!$save) {
    echo Locale_Translate::_("Don't know where to save");
    die;
}
// Checksum.
if (Checksum_Logic::get($usfm) != $checksum) {
Beispiel #7
0
 public function testNotificationTeamIdentifiers()
 {
     $database_modifications = Database_Modifications::getInstance();
     $database_modifications->recordNotification(array("phpunit1", "phpunit2"), "A", 1, 1, 2, 3, "old1", "mod1", "new1");
     $database_modifications->recordNotification(array("phpunit2", "phpunit1"), "B", 1, 1, 2, 3, "old2", "mod2", "new2");
     $database_modifications->recordNotification(array("phpunit3", "phpunit4"), "B", 1, 7, 8, 9, "old3", "mod3", "new3");
     $database_modifications->indexTrimAllNotifications();
     $ids = $database_modifications->getNotificationTeamIdentifiers("phpunit1", "A");
     $this->assertEquals(array(1), $ids);
     $ids = $database_modifications->getNotificationTeamIdentifiers("phpunit1", "B");
     $this->assertEquals(array(4), $ids);
 }
Beispiel #8
0
function processIdentifiers($user, $bible, $book, $chapter, $oldId, $newId, &$email)
{
    if ($oldId != 0) {
        $database_modifications = Database_Modifications::getInstance();
        $database_config_user = Database_Config_User::getInstance();
        $database_config_bible = Database_Config_Bible::getInstance();
        $database_bibles = Database_Bibles::getInstance();
        $database_history = Database_History::getInstance();
        $stylesheet = $database_config_bible->getExportStylesheet($bible);
        $old_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $oldId);
        $old_chapter_usfm = $old_chapter_usfm['oldtext'];
        $new_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $newId);
        $new_chapter_usfm = $new_chapter_usfm['newtext'];
        $timestamp = $database_modifications->getUserTimestamp($user, $bible, $book, $chapter, $newId);
        $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm);
        $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm);
        $verses = array_merge($old_verse_numbers, $new_verse_numbers);
        $verses = array_unique($verses);
        sort($verses, SORT_NUMERIC);
        foreach ($verses as $verse) {
            $old_verse_usfm = Filter_Usfm::getVerseText($old_chapter_usfm, $verse);
            $new_verse_usfm = Filter_Usfm::getVerseText($new_chapter_usfm, $verse);
            if ($old_verse_usfm != $new_verse_usfm) {
                $filter_text_old = new Filter_Text($bible);
                $filter_text_new = new Filter_Text($bible);
                $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
                $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible"));
                $filter_text_old->text_text = new Text_Text();
                $filter_text_new->text_text = new Text_Text();
                $filter_text_old->addUsfmCode($old_verse_usfm);
                $filter_text_new->addUsfmCode($new_verse_usfm);
                $filter_text_old->run($stylesheet);
                $filter_text_new->run($stylesheet);
                $old_html = $filter_text_old->html_text_standard->getInnerHtml();
                $new_html = $filter_text_new->html_text_standard->getInnerHtml();
                $old_text = $filter_text_old->text_text->get();
                $new_text = $filter_text_new->text_text->get();
                if ($old_text != $new_text) {
                    $modification = Filter_Diff::diff($old_text, $new_text);
                    $email .= "<div>";
                    $email .= Filter_Books::passageDisplay($book, $chapter, $verse);
                    $email .= " ";
                    $email .= $modification;
                    $email .= "</div>";
                    if ($database_config_user->getUserUserChangesNotificationsOnline($user)) {
                        $changeNotificationUsers = array($user);
                        $database_modifications->recordNotification($changeNotificationUsers, "☺", $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
                    }
                    $database_history->record($timestamp, $user, $bible, $book, $chapter, $verse, $old_html, $modification, $new_html);
                }
            }
        }
    }
}
Beispiel #9
0
 public function testTimestamp()
 {
     $database_modifications = Database_Modifications::getInstance();
     $database_modifications->recordUserSave("phpunit1", "bible", 1, 2, 3, "old1", 4, "new1");
     $time = $database_modifications->getUserTimestamp("phpunit1", "bible", 1, 2, 4);
     $this->assertGreaterThanOrEqual(time(), $time);
     $this->assertLessThanOrEqual(time() + 1, $time);
 }
Beispiel #10
0
 protected function tearDown()
 {
     $database_modifications = Database_Modifications::getInstance();
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications->deleteTeamDiffBible($this->bible);
     $database_bibles->deleteBible($this->bible);
     Filter_Rmdir::rmdir($this->repository);
     Filter_Rmdir::rmdir($this->newrepository);
 }
Beispiel #11
0
 public function testGetTeamDiffCount()
 {
     $database_bibles = Database_Bibles::getInstance();
     $database_modifications = Database_Modifications::getInstance();
     Bible_Logic::storeChapter("phpunit", 3, 1, "chapter text");
     Bible_Logic::storeChapter("phpunit2", 3, 3, "chapter text");
     Bible_Logic::storeChapter("phpunit2", 3, 5, "chapter text");
     $count = $database_modifications->getTeamDiffCount("phpunit");
     $this->assertEquals(1, $count);
     $count = $database_modifications->getTeamDiffCount("phpunit2");
     $this->assertEquals(2, $count);
     $count = $database_modifications->getTeamDiffCount("phpunit3");
     $this->assertEquals(0, $count);
 }