Skip to content

Commit

Permalink
Updated for 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdunn committed Mar 15, 2012
1 parent a99b292 commit 2633b54
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 100 deletions.
9 changes: 4 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

1. Download and upload the 'db_sync' folder to your Symphony 'extensions' folder.
2. Enable the extension by selecting "Database Synchroniser" in the list and choose Enable from the with-selected menu, then click Apply.
3. Modify the `query()` function in `symphony/lib/toolkit/class.mysql.php` adding the lines between `// Start database logger` and `// End database logger` from the `class.mysql.php.txt` file included with this extension. Place these at the very end of the function just before the `return` to ensure this query does not interfere with Profile performance logging.

## Warning

Since this extension requires a core file modification, changes you make to the MySQL class will be lost when you upgrade Symphony. Remember to add in the logging call back into `class.mysql.php` if you update Symphony!

As of version 0.7 the queries are stored in a file named `db_sync.sql` in your `/manifest` folder. This is unsecured, and therefore I strongly advise that this extension only be enabled on development environments.
As of version 0.7, queries are stored in a file named `db_sync.sql` in your `/manifest` folder. This file is visible to anyone, therefore I strongly advise that this extension only be enabled on development environments. Don't deploy it to production, or disable it entirely by looking for `db_sync` in Symphony's config file.

## Disclaimer

While this extension has worked well for my own projects, I can't guarantee its stability. My workflow when using a development/staging/production environment is to install this extension on the development server only. When making a release I pull the production database back to staging where I apply the db_sync SQL file. If all goes well after testing, I back up production and run the same db_sync file. The log is then flushed and I can continue developing towards another release.
While this extension has worked well for my own projects, I can't guarantee its stability for your own. My workflow when using a development/staging/production environment is to install this extension on the development server only. When making a release I pull the production database back to staging where I apply the db_sync SQL file. If all goes well after testing, I back up production and run the same db_sync file there. The file is then removed locally and I can continue developing towards another release.

Please, please, please back up your production database before applying any structural changes.
19 changes: 0 additions & 19 deletions class.mysql.php.txt

This file was deleted.

75 changes: 54 additions & 21 deletions extension.driver.php
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);

}

}

?>
}
2 changes: 1 addition & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="db_sync">
<extension id="db_sync" status="released" xmlns="http://symphony-cms.com/schemas/extension/1.0">
<name>Database Synchroniser</name>
<description>Log database changes to easily synchronise structure (sections, fields, pages) development and production databases, without affecting content.</description>
<repo type="github">https://github.com/nickdunn/db_sync</repo>
Expand Down
54 changes: 0 additions & 54 deletions lib/class.logquery.php

This file was deleted.

0 comments on commit 2633b54

Please sign in to comment.