-
-
Save rakeshtembhurne/3383f98fdc26ed71ed92 to your computer and use it in GitHub Desktop.
Croogo: Code for installing tables while activating croogo plugin
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
<?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