$database_config_bible = Database_Config_Bible::getInstance(); $send_receive = "send/receive:"; // Newer git versions would read their config from /root and then generate a fatal error. // Fix that here by setting the $HOME variable to something git can read. putenv("HOME=" . dirname(__FILE__)); $database_logs->log("Send/receive Bible" . " " . $bible, Filter_Roles::TRANSLATOR_LEVEL); // The git directory for this object. $directory = Filter_Git::git_directory($bible); $shelldirectory = escapeshellarg($directory); // Check that the repository directory is there. if (!is_dir($directory)) { $database_logs->log("{$send_receive} Cannot send and receive because the git repository was not found in the filesystem."); die; } // Sync the repository with the database. $success = Filter_Git::syncBible2Git($bible, $directory); // If the above does not succeed, then there is a serious problem. // It means that the git repository no longer reflects the data in the database. // This may lead to data corruption. // Through the repository this would then be propagated to other the systems. // The best thing to do is to remove the .git directory altogether so that it cannot propagate corrupt data. if (!$success) { Filter_Rmdir::rmdir("{$directory}/.git"); } // Commit the new data to the repository. // Log unusual things. if ($success) { $logs = array(); $command = "cd {$shelldirectory}; git add . 2>&1"; $logs[] = "{$send_receive} {$command}"; unset($result);
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) { foreach ($output as $line) { echo "{$line}\n"; } } $command = "cd {$shelldirectory}; git commit -a -m admin-sync"; echo "{$command}\n"; exec($command, $output, $exit_code);
public function testSyncBibleToGit3() { $database_bibles = Database_Bibles::getInstance(); $repository = $this->repository; $this->assertFileExists("{$repository}/.git"); $this->assertFileExists("{$repository}/Psalms/0/data"); $this->assertFileExists("{$repository}/Psalms/11/data"); $this->assertFileExists("{$repository}/Song of Solomon/2/data"); $this->assertFileNotExists("{$repository}/Exodus/1/data"); $database_bibles->storeChapter($this->bible, 19, 1, $this->song_of_solomon_2_data); $database_bibles->storeChapter($this->bible, 22, 2, $this->psalms_11_data); $database_bibles->storeChapter($this->bible, 19, 11, $this->song_of_solomon_2_data); Filter_Git::syncBible2Git($this->bible, $this->repository); $this->assertFileExists("{$repository}/.git"); $this->assertFileExists("{$repository}/Song of Solomon/2/data"); $this->assertFileExists("{$repository}/Psalms/1/data"); $this->assertFileExists("{$repository}/Song of Solomon/2/data"); $this->assertFileExists("{$repository}/Psalms/11/data"); $data = file_get_contents("{$repository}/Song of Solomon/2/data"); $this->assertEquals($this->psalms_11_data, $data); $data = file_get_contents("{$repository}/Psalms/11/data"); $this->assertEquals($this->song_of_solomon_2_data, $data); $data = file_get_contents("{$repository}/Psalms/1/data"); $this->assertEquals($this->song_of_solomon_2_data, $data); }