Skip to content

Instantly share code, notes, and snippets.

@rakeshtembhurne
Forked from bumuckl/activation method
Last active August 29, 2015 14:10
Show Gist options
  • Save rakeshtembhurne/3383f98fdc26ed71ed92 to your computer and use it in GitHub Desktop.
Save rakeshtembhurne/3383f98fdc26ed71ed92 to your computer and use it in GitHub Desktop.
Croogo: Code for installing tables while activating croogo plugin
<?php
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