Skip to content

Instantly share code, notes, and snippets.

@bumuckl
Created September 20, 2011 11:56
Show Gist options
  • Save bumuckl/1228933 to your computer and use it in GitHub Desktop.
Save bumuckl/1228933 to your computer and use it in GitHub Desktop.
Croogo plugin: Setup tables on activation
App::import('Model', 'CakeSchema');
App::import('Model', 'ConnectionManager');
include_once(APP.'plugins'.DS.'pluginname'.DS.'config'.DS.'schema'.DS.'schema.php');
$db = ConnectionManager::getDataSource('default');
//Get all available tables
$tables = $db->listSources();
$CakeSchema = new CakeSchema();
$SubSchema = new PluginnameSchema();
foreach ($SubSchema->tables as $table => $config) {
if (!in_array($table, $tables)) {
$db->execute($db->createSchema($SubSchema, $table));
}
}
//Ignore the cache since the tables wont be inside the cache at this point
@unlink(TMP . 'cache' . DS . 'models/cake_model_' . ConnectionManager::getSourceName($db). '_' . $db->config["database"] . '_list');
$db->sources(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment