Exemple #1
0
 protected function tearDown()
 {
     $database_notes = Database_Notes::getInstance();
     foreach ($this->note_identifiers as $identifier) {
         $database_notes->delete($identifier);
     }
 }
Exemple #2
0
 public static function checksum($identifiers)
 {
     $database_notes = Database_Notes::getInstance();
     $checksums = array();
     foreach ($identifiers as $identifier) {
         $checksums[] = $database_notes->getChecksum($identifier);
     }
     $checksum = implode("", $checksums);
     $checksum = md5($checksum);
     return $checksum;
 }
Exemple #3
0
 public function consultationNote($id)
 {
     $database_notes = Database_Notes::getInstance();
     $database_logs = Database_Logs::getInstance();
     $passage = $database_notes->getPassages($id);
     $passageText = Filter_Books::passagesDisplayInline($passage);
     $summary = $database_notes->getSummary($id);
     $contents = $database_notes->getContents($id);
     $contents = Filter_Html::html2text($contents);
     $session_logic = Session_Logic::getInstance();
     $username = $session_logic->currentUser();
     $database_logs->log("{$username} deleted / marked for deletion consultation note {$passageText} | {$summary} | {$contents}");
 }
Exemple #4
0
 /**
  * This imports one note from Bibledit-Gtk.
  * The note is available in $filename.
  * It returns the identifier of the note if imported successfully.
  * Else it returns NULL.
  */
 public static function importFromBibleditGtkFile($filename)
 {
     $note_identifier = NULL;
     if (file_exists($filename)) {
         // The note is in the format as used by Bibledit-Gtk.
         // The filename represents the note ID in Bibledit-Gtk.
         // This ID is not relevant for import.
         // Read the note.
         $note = file($filename);
         // line 0: date created.
         // This information is not used here. The same information will be in the logbook entries, see later.
         // line 1: user who created it.
         // This information is not used here. The same information will be in the logbook entries, see later.
         // line 2: note references.
         // Sample: Exod.29.23
         // Sample: Lev.26.16 Deut.28.22
         // It uses OSIS for book encoding.
         $passages = array();
         foreach (explode(" ", trim($note[2])) as $bibledit_gtk_reference) {
             $passages[] = Filter_Books::explodePassage($bibledit_gtk_reference);
         }
         // line 3: note category.
         $category = trim($note[3]);
         // line 4: Bible.
         $bible = trim($note[4]);
         // line 5: date modified.
         // This information is list since the note will be modified upon import.
         // line 6 and up: note text, "Logbook:", and logbook entries.
         // Summary will be taken from the first line.
         $summary = trim($note[6]);
         $contents = "";
         for ($i = 6; $i < count($note); $i++) {
             $contents .= $note[$i] . "\n";
         }
         // Store note.
         // (In client mode, upon sync to the server, these notes will be erased: Import them on the server).
         $database_notes = Database_Notes::getInstance();
         $note_identifier = $database_notes->storeNewNote($bible, 0, 0, 0, $summary, $contents, true);
         $database_notes->setPassages($note_identifier, $passages, true);
         $database_notes->setStatus($note_identifier, $category, true);
     }
     return $note_identifier;
 }
(at your option) any later version.

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";
Filter_Cli::assert();
$object = Filter_Cli::argument(@$argv, 1);
$database_config_bible = Database_Config_Bible::getInstance();
$database_notes = Database_Notes::getInstance();
$url = $database_config_bible->getRemoteRepositoryUrl($object);
$directory = Filter_Git::git_directory($object);
$consultationsfolder = $database_notes->mainFolder();
// Our data goes into the local repository.
echo Locale_Translate::_("Step 1/2:") . " ";
echo Locale_Translate::_("Exporting the local Bible data to the local repository") . "\n";
Filter_Git::syncBible2Git($object, $directory, true);
// Directory for use by the shell.
$shelldirectory = escapeshellarg($directory);
// Add and commit the data.
$command = "cd {$shelldirectory}; git add --all .";
echo "{$command}\n";
exec($command, $output, $exit_code);
echo "Exit code {$exit_code}\n";
if ($exit_code != 0) {
Exemple #6
0
 /**
  * handleEmailNew - handles an email received from $from with subject $subject and body $body.
  * Returns true if the mail was processed, else false.
  * The email is considered to have been processed if it created a new Consultation Note.
  */
 public function handleEmailNew($from, $subject, $body)
 {
     // Store the original subject.
     $originalSubject = $subject;
     // Check that the subject indicates that a new consultation note is to be created.
     $pos = strpos(strtolower($subject), "new note");
     if ($pos === false) {
         return false;
     }
     // There is a new note. Remove that bit from the $subject.
     $subject = substr($subject, 0, $pos) . substr($subject, $pos + 8);
     // Clean the subject line.
     $subject = trim($subject);
     $subject = str_replace(".", " ", $subject);
     $subject = str_replace(":", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     // Check that the $from address of the email belongs to an existing user.
     $from = Filter_Email::extractEmail($from);
     $database_users = Database_Users::getInstance();
     if (!$database_users->emailExists($from)) {
         return false;
     }
     $username = $database_users->getEmailToUser($from);
     // Extract book, chapter, verse, and note summary from the $subject
     $book = NULL;
     $chapter = NULL;
     $verse = NULL;
     $summary = NULL;
     $subject = explode(" ", $subject);
     if (count($subject) > 0) {
         $book = Filter_Books::interpretBook($subject[0]);
     }
     if (count($subject) > 1) {
         $chapter = Filter_Numeric::integer_in_string($subject[1]);
     }
     if (count($subject) > 2) {
         $verse = Filter_Numeric::integer_in_string($subject[2]);
     }
     unset($subject[0]);
     unset($subject[1]);
     unset($subject[2]);
     $summary = implode(" ", $subject);
     unset($subject);
     // Check book, chapter, verse, and summary. Give feedback if there's anything wrong.
     $noteCheck = "";
     if (!(is_numeric($book) && $book > 0)) {
         $noteCheck .= Locale_Translate::_("Unknown book");
     }
     if (!is_numeric($chapter)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown chapter");
     }
     if (!is_numeric($verse)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown verse");
     }
     if ($summary == NULL || $summary == "") {
         $noteCheck .= " " . Locale_Translate::_("Unknown summary");
     }
     // Mail user if the note could not be posted.
     $database_mail = Database_Mail::getInstance();
     if ($noteCheck != "") {
         $subject = Locale_Translate::_("Your new note could not be posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $noteCheck);
         return false;
     }
     // Clean the email's body.
     $body = Filter_Email::extractBody($body);
     // Post the note.
     $session_logic = Session_Logic::getInstance();
     $sessionuser = $session_logic->currentUser();
     $session_logic->setUsername($username);
     $database_notes = Database_Notes::getInstance();
     $identifier = $database_notes->storeNewNote("", $book, $chapter, $verse, $summary, $body, false);
     $this->handlerNewNote($identifier);
     $session_logic->setUsername($sessionuser);
     // Mail confirmation to the $username.
     $database_config_user = Database_Config_User::getInstance();
     if ($database_config_user->getUserNotifyMeOfMyPosts($username)) {
         $subject = Locale_Translate::_("Your new note was posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $body);
     }
     // Log operation.
     $database_logs = Database_Logs::getInstance();
     $database_logs->log("New note posted" . ":" . " " . $body);
     // Job done.
     return true;
 }
Exemple #7
0
 public function testAvailability()
 {
     $database_notes = Database_Notes::getInstance();
     $this->assertTrue($database_notes->available());
     $database_notes->set_availability(false);
     $this->assertFalse($database_notes->available());
     $database_notes->set_availability(true);
     $this->assertTrue($database_notes->available());
 }
Exemple #8
0
function die_if_databases_unhealthy_or_busy()
{
    $database_notes = Database_Notes::getInstance();
    $available = true;
    if (!$database_notes->healthy()) {
        $available = false;
    }
    if (!$database_notes->checksums_healthy()) {
        $available = false;
    }
    if (!$database_notes->available()) {
        $available = false;
    }
    if (!$available) {
        $database_logs = Database_Logs::getInstance();
        $database_logs->log("Notes databases are unhealthy or unavailable", Filter_Roles::TRANSLATOR_LEVEL);
        die;
    }
}