/**
* CSVファイルを書きだす
*
* @param string $configKeyName
* @param string $path
* @return boolean
* @access protected
*/
function _writeCsv($configKeyName, $plugin, $path, $exclude = array())
{
$pluginTables = array();
if ($plugin != 'core') {
$pluginPath = BcUtil::getSchemaPath($plugin);
$Folder = new Folder($pluginPath);
$files = $Folder->read(true, true, false);
$pluginTables = $files[1];
foreach ($pluginTables as $key => $pluginTable) {
if (preg_match('/^(.+)\\.php$/', $pluginTable, $matches)) {
$pluginTables[$key] = $matches[1];
} else {
unset($pluginTables[$key]);
}
}
}
$pluginKey = Inflector::underscore($plugin);
$db = ConnectionManager::getDataSource($configKeyName);
$db->cacheSources = false;
$tables = $db->listSources();
$result = true;
foreach ($tables as $table) {
if (preg_match("/^" . $db->config['prefix'] . "([^_].+)\$/", $table, $matches) && !preg_match("/^" . Configure::read('BcEnv.pluginDbPrefix') . "[^_].+\$/", $matches[1])) {
$table = $matches[1];
if (in_array($table, $exclude)) {
continue;
}
if ($pluginKey != 'core') {
// プラグインの場合は対象プラグイン名が先頭にない場合スキップ
//if (!preg_match("/^" . $pluginKey . "_([^_].+)$/", $table)) {
if (!in_array($table, $pluginTables)) {
// メールプラグインの場合、先頭に、「mail_」 がなくとも 末尾にmessagesがあれば対象とする
if ($pluginKey != 'mail') {
continue;
} elseif (!preg_match("/messages\$/", $table)) {
continue;
}
}
}
if (!$db->writeCsv(array('path' => $path . $table . '.csv', 'encoding' => 'SJIS', 'init' => false, 'plugin' => $plugin == 'core' ? null : $plugin))) {
$result = false;
}
}
}
return $result;
}