-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,76 @@ | ||
<?php | ||
|
||
require_once(EXTENSIONS . '/db_sync/lib/class.logquery.php'); | ||
|
||
Class extension_db_sync extends Extension { | ||
|
||
public function about() { | ||
|
||
public static $meta_written = FALSE; | ||
|
||
public function getSubscribedDelegates() { | ||
return array( | ||
'name' => 'Database Synchroniser', | ||
'version' => '0.9.1', | ||
'release-date' => '2011-02-10', | ||
'author' => array( | ||
'name' => 'Nick Dunn, Richard Warrender', | ||
'website' => 'http://airlock.com', | ||
'email' => 'nick.dunn@airlock.com' | ||
), | ||
'description' => 'Logs structural database changes to allow syncing between builds.' | ||
array( | ||
'page' => '/backend/', | ||
'delegate' => 'PostQueryExecution', | ||
'callback' => 'log' | ||
) | ||
); | ||
} | ||
|
||
public function install() { | ||
Symphony::Configuration()->set('enabled', 'yes', 'db_sync'); | ||
Administration::instance()->saveConfig(); | ||
return true; | ||
return TRUE; | ||
} | ||
|
||
public function uninstall() { | ||
if (file_exists(MANIFEST . '/db_sync.sql')) unlink(MANIFEST . '/db_sync.sql'); | ||
|
||
Symphony::Configuration()->remove('db_sync'); | ||
Administration::instance()->saveConfig(); | ||
} | ||
|
||
public static function addToLogFile($line) { | ||
public static function log($context) { | ||
if(Symphony::Configuration()->get('enabled', 'db_sync') == 'no') return; | ||
|
||
$query = $context['query']; | ||
|
||
$tbl_prefix = Symphony::Configuration()->get('tbl_prefix', 'database'); | ||
|
||
/* FILTERS */ | ||
// only structural changes, no SELECT statements | ||
if (!preg_match('/^(insert|update|delete|create|drop|alter|rename)/i', $query)) return; | ||
// un-tracked tables (sessions, cache, authors) | ||
if (preg_match("/{$tbl_prefix}(authors|cache|forgotpass|sessions)/i", $query)) return; | ||
// content updates in tbl_entries (includes tbl_entries_fields_*) | ||
if (preg_match('/^(insert|delete|update)/i', $query) && preg_match("/({$config->tbl_prefix}entries)/i", $query)) return; | ||
|
||
$line = ''; | ||
|
||
if(self::$meta_written == FALSE) { | ||
|
||
$line .= "\n" . '-- ' . date('Y-m-d H:i:s', time()); | ||
|
||
$author = Administration::instance()->Author; | ||
if (isset($author)) $line .= ', ' . $author->getFullName(); | ||
|
||
$url = Administration::instance()->getCurrentPageURL(); | ||
if (!is_null($url)) $line .= ', ' . $url; | ||
|
||
$line .= "\n"; | ||
|
||
self::$meta_written = TRUE; | ||
|
||
} | ||
|
||
$query = trim($query); | ||
|
||
// append query delimeter if it doesn't exist | ||
if (!preg_match('/;$/', $query)) $query .= ";"; | ||
|
||
$line .= $query . "\n"; | ||
|
||
$logfile = MANIFEST . '/db_sync.sql'; | ||
$handle = @fopen($logfile, 'a'); | ||
fwrite($handle, $line); | ||
fclose($handle); | ||
} | ||
fclose($handle); | ||
|
||
} | ||
|
||
} | ||
|
||
?> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.