* add tools
This commit is contained in:
Executable
+259
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is used to check the language items and actions.
|
||||
*/
|
||||
/* Define an emtpty control class as the base class of every module. */
|
||||
class control {}
|
||||
$config = new stdclass();
|
||||
$config->global = new stdclass();
|
||||
$config->global->flow = 'full';
|
||||
|
||||
/* set module root path and included the resource of group module. */
|
||||
$moduleRoot = '../module/';
|
||||
include $moduleRoot . '/group/lang/resource.php';
|
||||
foreach(glob($moduleRoot . '/group/ext/lang/zh-cn/*.php') as $resourceFile)
|
||||
{
|
||||
include $resourceFile;
|
||||
}
|
||||
|
||||
$lang->productCommon = '';
|
||||
$lang->projectCommon = '';
|
||||
|
||||
$whiteList[] = 'api-getsessionid';
|
||||
$whiteList[] = 'admin-setflow';
|
||||
$whiteList[] = 'bug-buildtemplates';
|
||||
$whiteList[] = 'bug-sendmail';
|
||||
$whiteList[] = 'board-managechild';
|
||||
$whiteList[] = 'custom-menu';
|
||||
$whiteList[] = 'company-create';
|
||||
$whiteList[] = 'company-delete';
|
||||
$whiteList[] = 'file-buildexporttpl';
|
||||
$whiteList[] = 'file-buildform';
|
||||
$whiteList[] = 'file-printfiles';
|
||||
$whiteList[] = 'file-export2csv';
|
||||
$whiteList[] = 'file-export2xml';
|
||||
$whiteList[] = 'file-export2html';
|
||||
$whiteList[] = 'file-export2excel';
|
||||
$whiteList[] = 'file-export2word';
|
||||
$whiteList[] = 'file-senddownheader';
|
||||
$whiteList[] = 'file-read';
|
||||
$whiteList[] = 'help-field';
|
||||
$whiteList[] = 'index-testext';
|
||||
$whiteList[] = 'productplan-commonaction';
|
||||
$whiteList[] = 'project-managechilds';
|
||||
$whiteList[] = 'project-tips';
|
||||
$whiteList[] = 'project-commonaction';
|
||||
$whiteList[] = 'project-sendmail';
|
||||
$whiteList[] = 'release-commonaction';
|
||||
$whiteList[] = 'task-commonaction';
|
||||
$whiteList[] = 'task-sendmail';
|
||||
$whiteList[] = 'testtask-sendmail';
|
||||
$whiteList[] = 'user-login';
|
||||
$whiteList[] = 'user-deny';
|
||||
$whiteList[] = 'user-logout';
|
||||
$whiteList[] = 'user-setreferer';
|
||||
$whiteList[] = 'svn-run';
|
||||
$whiteList[] = 'git-run';
|
||||
$whiteList[] = 'admin-ignore';
|
||||
$whiteList[] = 'admin-register';
|
||||
$whiteList[] = 'admin-win2unix';
|
||||
$whiteList[] = 'admin-bind';
|
||||
$whiteList[] = 'admin-certifyztemail';
|
||||
$whiteList[] = 'admin-certifyztmobile';
|
||||
$whiteList[] = 'admin-ztcompany';
|
||||
$whiteList[] = 'story-commonaction';
|
||||
$whiteList[] = 'story-sendmail';
|
||||
$whiteList[] = 'webapp-ajaxaddview';
|
||||
$whiteList[] = 'report-remind';
|
||||
$whiteList[] = 'sso-auth';
|
||||
$whiteList[] = 'sso-depts';
|
||||
$whiteList[] = 'sso-users';
|
||||
$whiteList[] = 'sso-login';
|
||||
$whiteList[] = 'sso-logout';
|
||||
$whiteList[] = 'sso-bind';
|
||||
$whiteList[] = 'sso-getuserpairs';
|
||||
$whiteList[] = 'sso-getbindusers';
|
||||
$whiteList[] = 'sso-binduser';
|
||||
$whiteList[] = 'sso-createuser';
|
||||
$whiteList[] = 'sso-gettodolist';
|
||||
$whiteList[] = 'mail-asyncsend';
|
||||
$whiteList[] = 'user-reset';
|
||||
$whiteList[] = 'product-showerrornone';
|
||||
$whiteList[] = 'tutorial-start';
|
||||
$whiteList[] = 'tutorial-index';
|
||||
$whiteList[] = 'tutorial-quit';
|
||||
$whiteList[] = 'tutorial-wizard';
|
||||
$whiteList[] = 'my-buildcontactlists';
|
||||
$whiteList[] = 'mail-ztcloud';
|
||||
$whiteList[] = 'doc-diff';
|
||||
$whiteList[] = 'testreport-commonaction';
|
||||
$whiteList[] = 'testsuite-library';
|
||||
$whiteList[] = 'testsuite-createlib';
|
||||
$whiteList[] = 'testsuite-createcase';
|
||||
$whiteList[] = 'testsuite-libview';
|
||||
|
||||
|
||||
/* checking actions of every module. */
|
||||
echo '-------------action checking-----------------' . "\n";
|
||||
foreach(glob($moduleRoot . '*') as $modulePath)
|
||||
{
|
||||
$moduleName = basename($modulePath);
|
||||
if(strpos('install|upgrade|convert|common|misc|editor', $moduleName) !== false) continue;
|
||||
$controlFile = $modulePath . '/control.php';
|
||||
if(file_exists($controlFile))
|
||||
{
|
||||
include $controlFile;
|
||||
if(class_exists($moduleName))
|
||||
{
|
||||
if($moduleName == 'block') continue;
|
||||
$class = new ReflectionClass($moduleName);
|
||||
$methods = $class->getMethods();
|
||||
foreach($methods as $method)
|
||||
{
|
||||
$methodRef = new ReflectionMethod($method->class, $method->name);
|
||||
if($methodRef->isPublic() and strpos($method->name, '__') === false)
|
||||
{
|
||||
$methodName = $method->name;
|
||||
if(in_array($moduleName . '-' . strtolower($method->name), $whiteList)) continue;
|
||||
if(strpos($methodName, 'ajax') !== false) continue;
|
||||
|
||||
$exits = false;
|
||||
if(isset($lang->resource->$moduleName))
|
||||
{
|
||||
foreach($lang->resource->$moduleName as $key => $label)
|
||||
{
|
||||
if(strtolower($methodName) == strtolower($key)) $exits = true;
|
||||
}
|
||||
}
|
||||
if(!$exits) echo $moduleName . "\t" . $methodName . " not in the list. \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Checking extension files. */
|
||||
$extControlFiles = glob($modulePath . '/ext/control/*.php');
|
||||
if($extControlFiles)
|
||||
{
|
||||
foreach($extControlFiles as $extControlFile)
|
||||
{
|
||||
$methodFile = substr($extControlFile, strrpos($extControlFile, '/') + 1);
|
||||
$methodName = substr($methodFile, 0, strpos($methodFile, '.'));
|
||||
if(in_array($moduleName . '-' . strtolower($methodName), $whiteList)) continue;
|
||||
if(strpos($methodName, 'ajax') !== false) continue;
|
||||
|
||||
$exits = false;
|
||||
foreach($lang->resource->$moduleName as $key => $label)
|
||||
{
|
||||
if(strtolower($methodName) == strtolower($key)) $exits = true;
|
||||
}
|
||||
if(!$exits) echo $moduleName . "\t" . $methodName . " not in the list. \n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* checking actions of every module. */
|
||||
echo '-------------lang checking-----------------' . "\n";
|
||||
include '../module/common/lang/zh-cn.php';
|
||||
include '../config/config.php';
|
||||
foreach(glob($moduleRoot . '*') as $modulePath)
|
||||
{
|
||||
unset($lang);
|
||||
$moduleName = basename($modulePath);
|
||||
$mainLangFile = $modulePath . '/lang/zh-cn.php';
|
||||
if(!file_exists($mainLangFile)) continue;
|
||||
$mainLines = file($mainLangFile);
|
||||
|
||||
foreach($config->langs as $langKey => $langName)
|
||||
{
|
||||
if($langKey == 'zh-cn' or $langKey == 'zh-tw') continue;
|
||||
$langFile = $modulePath . '/lang/' . $langKey . '.php';
|
||||
if(!file_exists($langFile)) continue;
|
||||
$lines = file($langFile);
|
||||
foreach($mainLines as $lineNO => $line)
|
||||
{
|
||||
if(strpos($line, '$lang') === false)
|
||||
{
|
||||
//if($line != $lines[$lineNO]) echo $moduleName . ' ' . $langKey . ' ' . $lineNO . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strpos($line, '=') !== false)
|
||||
{
|
||||
list($mainKey, $mainValue) = explode('=', $line);
|
||||
list($key, $value) = explode('=', $lines[$lineNO]);
|
||||
}
|
||||
if((strpos($line, '=') === false and $line != $lines[$lineNO]) or trim($mainKey) != trim($key))
|
||||
{
|
||||
$key = trim($key);
|
||||
$lineNO = $lineNO + 1;
|
||||
echo "module $moduleName need checking, command is:";
|
||||
echo " vim -O +$lineNO ../module/$moduleName/lang/zh-cn.php +$lineNO ../module/$moduleName/lang/en.php \n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(glob($modulePath . '/ext/lang/zh-cn/*.php') as $extMainLangFile)
|
||||
{
|
||||
$extMainLines = file($extMainLangFile);
|
||||
$extLangFile = basename($extMainLangFile);
|
||||
$extEnFile = $modulePath . '/ext/lang/en/' . $extLangFile;
|
||||
$extLines = file($extEnFile);
|
||||
foreach($extMainLines as $lineNO => $line)
|
||||
{
|
||||
if(strpos($line, '$lang') === false)
|
||||
{
|
||||
//if($line != $lines[$lineNO]) echo $moduleName . ' ' . $langKey . ' ' . $lineNO . "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
list($mainKey, $mainValue) = explode('=', $line);
|
||||
list($key, $value) = explode('=', $extLines[$lineNO]);
|
||||
if(trim($mainKey) != trim($key))
|
||||
{
|
||||
$key = trim($key);
|
||||
$lineNO = $lineNO + 1;
|
||||
echo "module $moduleName need checking, command is:";
|
||||
echo " vim -O +$lineNO ../../module/$moduleName/ext/lang/zh-cn/$extLangFile +$lineNO ../../module/$moduleName/ext/lang/en/$extLangFile \n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '-------------php5.4 synatax checking-----------------' . "\n";
|
||||
class app {function loadLang() {}}
|
||||
$app = new app;
|
||||
$lang = new stdclass();
|
||||
|
||||
error_reporting(E_WARNING | E_STRICT );
|
||||
foreach(glob($moduleRoot . '*') as $modulePath)
|
||||
{
|
||||
$moduleName = basename($modulePath);
|
||||
$cnLangFile = $modulePath . '/lang/zh-cn.php';
|
||||
$enLangFile = $modulePath . '/lang/en.php';
|
||||
$configFile = $modulePath . '/config.php';
|
||||
|
||||
if(!isset($lang->$moduleName)) $lang->$moduleName = new stdclass();
|
||||
if(!isset($config->$moduleName)) $config->$moduleName = new stdclass();
|
||||
if(file_exists($cnLangFile)) include $cnLangFile;
|
||||
if(file_exists($enLangFile)) include $enLangFile;
|
||||
if(file_exists($configFile)) include $configFile;
|
||||
}
|
||||
|
||||
echo '-------------demo data checking. -----------------' . "\n";
|
||||
$demoSQL = file("../db/demo.sql");
|
||||
foreach($demoSQL as $line => $sql)
|
||||
{
|
||||
if(strpos($sql, 'INSERT') === false) continue;
|
||||
|
||||
if(strpos($sql, $config->db->prefix . 'config') !== false or
|
||||
strpos($sql, $config->db->prefix . 'company') !== false or
|
||||
strpos($sql, $config->db->prefix . 'group') !== false)
|
||||
{
|
||||
die('line ' . ($line + 1) . " has error\n");
|
||||
}
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
$langType = 'zh-tw';
|
||||
$langDesc = 'zh-tw';
|
||||
if(empty($langType)) die('lang') . "\n";
|
||||
foreach(glob('../module/*') as $moduleName)
|
||||
{
|
||||
$moduleLangPath = realpath($moduleName) . '/lang/';
|
||||
$defaultLangFile = $moduleLangPath . 'zh-cn.php';
|
||||
$targetLangFile = $moduleLangPath . $langType . '.php';
|
||||
if(!file_exists($defaultLangFile)) continue;
|
||||
|
||||
system("cconv -f utf-8 -t UTF8-TW $defaultLangFile > $targetLangFile");
|
||||
$defaultLang = file_get_contents($targetLangFile);
|
||||
$targetLang = str_replace('zh-cn', $langDesc, $defaultLang);
|
||||
file_put_contents($targetLangFile, $targetLang);
|
||||
}
|
||||
?>
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
$langType = $argv[1];
|
||||
$langDesc = $argv[2];
|
||||
if(empty($langType)) die('lang') . "\n";
|
||||
foreach(glob('../module/*') as $moduleName)
|
||||
{
|
||||
$moduleLangPath = realpath($moduleName) . '/lang/';
|
||||
$defaultLangFile = $moduleLangPath . 'zh-cn.php';
|
||||
$targetLangFile = $moduleLangPath . $langType . '.php';
|
||||
if(!file_exists($defaultLangFile)) continue;
|
||||
|
||||
$defaultLang = file_get_contents($defaultLangFile);
|
||||
$targetLang = str_replace('zh-cn', $langDesc, $defaultLang);
|
||||
file_put_contents($targetLangFile, $targetLang);
|
||||
}
|
||||
?>
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
class control {}
|
||||
$moduleRoot = rtrim($argv[1], '/') . '/';
|
||||
|
||||
foreach(glob($moduleRoot . '*') as $modulePath)
|
||||
{
|
||||
$moduleName = basename($modulePath);
|
||||
$controlFile = $modulePath . '/control.php';
|
||||
if(file_exists($controlFile))
|
||||
{
|
||||
include $controlFile;
|
||||
$lines = explode("\n", file_get_contents($controlFile));
|
||||
if(class_exists($moduleName))
|
||||
{
|
||||
$class = new ReflectionClass($moduleName);
|
||||
$methods = $class->getMethods();
|
||||
foreach($methods as $method)
|
||||
{
|
||||
$methodRef = new ReflectionMethod($method->class, $method->name);
|
||||
if($methodRef->isPublic() and strpos($method->name, '__') === false)
|
||||
{
|
||||
echo "\$lang['action']['$moduleName']['$method->name'] = '$method->name';\n";
|
||||
}
|
||||
}
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
$langType = empty($argv[1]) ? 'zh-cn' : $argv[1];
|
||||
$modules = glob('../module/*');
|
||||
$maxLength = 0;
|
||||
foreach($modules as $modulePath)
|
||||
{
|
||||
$moduleName = basename($modulePath);
|
||||
if(strlen($moduleName) > $maxLength) $maxLength = strlen($moduleName);
|
||||
}
|
||||
|
||||
foreach($modules as $modulePath)
|
||||
{
|
||||
$moduleName = basename($modulePath);
|
||||
if($moduleName == 'help' or $moduleName == 'editor') continue;
|
||||
$langFile = $modulePath . "/lang/$langType.php";
|
||||
if(!file_exists($langFile)) continue;
|
||||
include $langFile;
|
||||
|
||||
$moduleTitle = '';
|
||||
if(isset($lang->$moduleName->common))
|
||||
{
|
||||
$moduleTitle = $lang->$moduleName->common;
|
||||
}
|
||||
|
||||
echo "\$lang->editor->modules['$moduleName'] " . str_pad('', $maxLength - strlen($moduleName)) . "= '$moduleTitle';\n";
|
||||
|
||||
}
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* The control file of common module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2013 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
|
||||
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
|
||||
* @author Chen congzhi <congzhi@cnezsoft.com>
|
||||
* @package common
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
include '../config/config.php';
|
||||
|
||||
$modules = array();
|
||||
$moduleRoot = realpath('../module/') . '/';
|
||||
|
||||
if(is_dir($moduleRoot))
|
||||
{
|
||||
if($dh = opendir($moduleRoot))
|
||||
{
|
||||
while($module = readdir($dh))
|
||||
{
|
||||
if(strpos(basename($module), '.') === false) $modules[] = $module;
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
die("The module you input does not exist. \n");
|
||||
}
|
||||
|
||||
foreach($modules as $module)
|
||||
{
|
||||
/* 设定各个目录。*/
|
||||
$extRoot = $moduleRoot . DIRECTORY_SEPARATOR. $module . DIRECTORY_SEPARATOR . 'ext';
|
||||
$extControl = $extRoot . DIRECTORY_SEPARATOR . 'control';
|
||||
$extModel = $extRoot . DIRECTORY_SEPARATOR . 'model';
|
||||
$extView = $extRoot . DIRECTORY_SEPARATOR . 'view';
|
||||
$extCSS = $extRoot . DIRECTORY_SEPARATOR . 'css';
|
||||
$extJS = $extRoot . DIRECTORY_SEPARATOR . 'js';
|
||||
$extConfig = $extRoot . DIRECTORY_SEPARATOR . 'config';
|
||||
$extLang = $extRoot . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/* 建立各个扩展目录 */
|
||||
if(!file_exists($extRoot)) mkdir($extRoot, 0777);
|
||||
if(!file_exists($extControl)) mkdir($extControl, 0777);
|
||||
if(!file_exists($extModel)) mkdir($extModel, 0777);
|
||||
if(!file_exists($extView)) mkdir($extView, 0777);
|
||||
if(!file_exists($extCSS)) mkdir($extCSS, 0777);
|
||||
if(!file_exists($extJS)) mkdir($extJS, 0777);
|
||||
if(!file_exists($extConfig)) mkdir($extConfig, 0777);
|
||||
if(!file_exists($extLang)) mkdir($extLang, 0777);
|
||||
|
||||
/* Touch .gitkeep file. */
|
||||
touch($extControl . '/.gitkeep');
|
||||
touch($extModel . '/.gitkeep');
|
||||
touch($extView . '/.gitkeep');
|
||||
touch($extCSS . '/.gitkeep');
|
||||
touch($extJS . '/.gitkeep');
|
||||
touch($extConfig . '/.gitkeep');
|
||||
|
||||
/* 创建语言目录。*/
|
||||
$langs = array_keys($config->langs);
|
||||
foreach($langs as $lang)
|
||||
{
|
||||
$langPath = $extLang . $lang;
|
||||
if(!file_exists($langPath)) mkdir($langPath, 0777);
|
||||
touch($langPath . '/.gitkeep');
|
||||
}
|
||||
|
||||
echo "init $module ... \n";
|
||||
}
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is used to compress css and js files.
|
||||
*/
|
||||
|
||||
$baseDir = dirname(dirname(__FILE__));
|
||||
|
||||
//--------------------------------- PROCESS JS FILES ------------------------------ //
|
||||
|
||||
/* Set jsRoot and jqueryRoot. */
|
||||
$jsRoot = $baseDir . '/www/js/';
|
||||
$jqueryRoot = $jsRoot . 'jquery/';
|
||||
|
||||
/* Set js files to combined. */
|
||||
$jsFiles[] = $jqueryRoot . 'lib.js';
|
||||
$jsFiles[] = $jsRoot . 'zui/min.js';
|
||||
$jsFiles[] = $jsRoot . 'my.full.js';
|
||||
$jsFiles[] = $jqueryRoot . 'chosen/min.js';
|
||||
$jsFiles[] = $jqueryRoot . 'treeview/min.js';
|
||||
$jsFiles[] = $jqueryRoot . 'datetimepicker/min.js';
|
||||
$jsFiles[] = $jsRoot . 'chartjs/chart.min.js';
|
||||
|
||||
/* Combine these js files. */
|
||||
$allJSFile = $jsRoot . 'all.js';
|
||||
$jsCode = '';
|
||||
foreach($jsFiles as $jsFile) $jsCode .= "\n". file_get_contents($jsFile);
|
||||
file_put_contents($allJSFile, $jsCode);
|
||||
|
||||
/* Compress it. */
|
||||
`java -jar ~/bin/yuicompressor/build/yuicompressor.jar --type js $allJSFile -o $allJSFile`;
|
||||
|
||||
//-------------------------------- PROCESS CSS FILES ------------------------------ //
|
||||
|
||||
/* Define the themeRoot. */
|
||||
$themeRoot = $baseDir . '/www/theme/';
|
||||
|
||||
/* Iinclude config and lang file to get langs and themes. */
|
||||
include $baseDir . '/config/config.php';
|
||||
$lang = new stdclass();
|
||||
$lang->productCommon = '';
|
||||
$lang->projectCommon = '';
|
||||
include $baseDir . '/module/common/lang/zh-cn.php';
|
||||
$langs = array_keys($config->langs);
|
||||
$themes = array_keys($lang->themes);
|
||||
|
||||
/* Create css files for every them and every lang. */
|
||||
$zuiCode = str_replace('../fonts', '../zui/fonts', file_get_contents($themeRoot . 'zui/css/min.css'));
|
||||
foreach($langs as $lang)
|
||||
{
|
||||
foreach($themes as $theme)
|
||||
{
|
||||
/* Common css files. */
|
||||
$cssCode = $zuiCode;
|
||||
$cssCode .= file_get_contents($themeRoot . 'default/style.css');
|
||||
$cssCode .= file_get_contents($jqueryRoot . 'chosen/min.css');
|
||||
$cssCode .= file_get_contents($themeRoot . 'default/treeview.css');
|
||||
$cssCode .= file_get_contents($jqueryRoot . 'datetimepicker/min.css');
|
||||
|
||||
/* Css file for current lang and current them. */
|
||||
$cssCode .= file_get_contents($themeRoot . "lang/$lang.css");
|
||||
if($theme != 'default')
|
||||
{
|
||||
$themCode = file_get_contents($themeRoot . $theme . '/style.css');
|
||||
$cssCode .= str_replace('./images', "../$theme/images", $themCode);
|
||||
}
|
||||
|
||||
/* Combine them. */
|
||||
$cssFile = $themeRoot . "default/$lang.$theme.css";
|
||||
file_put_contents($cssFile, $cssCode);
|
||||
|
||||
/* Compress it. */
|
||||
`java -jar ~/bin/yuicompressor/build/yuicompressor.jar --type css $cssFile -o $cssFile`;
|
||||
}
|
||||
}
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
include '../config/config.php';
|
||||
connectDB();
|
||||
|
||||
$databases[] = 'zentao_03';
|
||||
$databases[] = 'zentao_04';
|
||||
$databases[] = 'zentao_05';
|
||||
$databases[] = 'zentao_06';
|
||||
$databases[] = 'zentao_10';
|
||||
$databases[] = 'zentao_101';
|
||||
$databases[] = 'zentao_11';
|
||||
$databases[] = 'zentao_12';
|
||||
$databases[] = 'zentao_13';
|
||||
$databases[] = 'zentao_14';
|
||||
$databases[] = 'zentao_15';
|
||||
|
||||
if(!isset($argv[1])) die(__FILE__ . ' restore' . "\n");
|
||||
|
||||
$cmd = $argv[1];
|
||||
if($cmd == 'backup') backupDB();
|
||||
if($cmd == 'restore') restore();
|
||||
|
||||
/* Backup new installed database. */
|
||||
function backupDB()
|
||||
{
|
||||
global $databases;
|
||||
foreach($databases as $database)
|
||||
{
|
||||
$backupDatabase = "back_$database";
|
||||
mysql_query("DROP DATABASE $backupDatabase");
|
||||
mysql_query("CREATE DATABASE $backupDatabase");
|
||||
$cmd = "mysqldump -u root $database > $database.sql;\n";
|
||||
$cmd .= "mysql -uroot $backupDatabase < $database.sql;\n";
|
||||
$cmd .= "rm -fr $database.sql";
|
||||
system($cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore stored backup databases. */
|
||||
function restore()
|
||||
{
|
||||
global $databases;
|
||||
foreach($databases as $database)
|
||||
{
|
||||
$backupDatabase = "back_$database";
|
||||
mysql_query("DROP DATABASE $database");
|
||||
mysql_query("CREATE DATABASE $database");
|
||||
$cmd = "mysqldump -u root $backupDatabase > $database.sql;\n";
|
||||
$cmd .= "mysql -uroot $database < $database.sql;\n";
|
||||
$cmd .= "rm -fr $database.sql";
|
||||
system($cmd);
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect to database. */
|
||||
function connectDB()
|
||||
{
|
||||
global $config;
|
||||
mysql_connect($config->db->host, $config->db->user, $config->db->password);
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#replace title
|
||||
foreachd(){
|
||||
for file in `ls $1`
|
||||
do
|
||||
if [ -d $1/$file ]
|
||||
then
|
||||
echo "into dir $1/$file"
|
||||
foreachd $1/$file
|
||||
elif [ -f $1/$file ]
|
||||
then
|
||||
# sed -i '1,11s/\@license.*$/\@license ZPL \(http:\/\/zpl\.pub\/page\/zplv11\.html\)/g' $1/$file
|
||||
sed -i '1,11s/\@copyright.*$/\@copyright Copyright 2009-2015 青岛易软天创网络科技有限公司\(QingDao Nature Easy Soft Network Technology Co,LTD, www\.cnezsoft\.com\)/g' $1/$file
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
foreachd $1
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* This file is used to sync extension files to the target pms directory.
|
||||
*
|
||||
* @author chunsheng wang chunsheng@cnezsoft.com
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
//sudo pecl install channel://pecl.php.net/inotify-0.1.5
|
||||
|
||||
//extension=inotify.so" to php.ini
|
||||
|
||||
/* Get params from argvs. */
|
||||
if(!isset($argv[1])) die("php syncext.php from target sleep\n");
|
||||
$from = $argv[1];
|
||||
$target = isset($argv[2]) ? $argv[2] : '/home/z/zentaopms';
|
||||
$sleep = isset($argv[3]) ? $argv[3] : 5;
|
||||
|
||||
/* sync files. */
|
||||
while(true)
|
||||
{
|
||||
syncFiles(getFiles($from), $from, $target);
|
||||
sleep($sleep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files under a directory recursive.
|
||||
*
|
||||
* @param string $dir
|
||||
* @param array $exceptions
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function getFiles($dir, $exceptions = array())
|
||||
{
|
||||
static $files = array();
|
||||
|
||||
if(!is_dir($dir)) return $files;
|
||||
|
||||
$dir = realpath($dir) . '/';
|
||||
$entries = scandir($dir);
|
||||
|
||||
foreach($entries as $entry)
|
||||
{
|
||||
if($entry == '.' or $entry == '..' or $entry == '.svn' or $entry == 'db') continue;
|
||||
if(in_array($entry, $exceptions)) continue;
|
||||
|
||||
$fullEntry = $dir . $entry;
|
||||
if(is_file($fullEntry))
|
||||
{
|
||||
$files[] = $dir . $entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
$nextDir = $dir . $entry;
|
||||
getFiles($nextDir);
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync extension files to target.
|
||||
*
|
||||
* @param array $files
|
||||
* @param string $from
|
||||
* @param string $target
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function syncFiles($files, $from, $target)
|
||||
{
|
||||
$from = realpath($from);
|
||||
$target = realpath($target);
|
||||
static $copied = array();
|
||||
|
||||
foreach($files as $file)
|
||||
{
|
||||
$relativePath = str_replace($from, '', $file);
|
||||
$targetFile = $target . $relativePath;
|
||||
$targetPath = dirname($targetFile);
|
||||
|
||||
/* If file not exists, remove the target. */
|
||||
if(!is_file($file))
|
||||
{
|
||||
@unlink($targetFile);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!is_dir($targetPath)) mkdir($targetPath, 0755, true);
|
||||
$ctime = filectime($file);
|
||||
if(!isset($copied[$file]) or $copied[$file] != $ctime)
|
||||
{
|
||||
copy($file, $targetFile);
|
||||
$copied[$file] = $ctime;
|
||||
echo "$file copyed\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This shell is used to sync extension files.
|
||||
#
|
||||
# @author chunsheng wang<chunsheng@cnezsoft.com>
|
||||
# @author yidong wang<wangyidong@cnezsoft.com>
|
||||
#
|
||||
|
||||
# Judge the params, must give $src and $dest.
|
||||
if [ $# -lt 2 ]; then
|
||||
echo './syncext.sh src dest'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Judge inotifywait tool exists or not.
|
||||
which inotifywait > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'No inotifywait. Please install inotify-tools, for debian or ubuntun run apt-get install inotify-tools.';
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get $src and $dest.
|
||||
src=$1/
|
||||
dest=$2/
|
||||
|
||||
# Rsync when the shell load first.
|
||||
rsync -aqP --exclude="db/" $src $dest
|
||||
echo `date "+%H:%M:%S"` sync $src to $dest succssfully.
|
||||
|
||||
# Watch the $src directory, and sync files to destination.
|
||||
inotifywait -mrq --event create,modify,delete,move --format '%w %e %f' $src |\
|
||||
while read watcher event file ; do
|
||||
|
||||
# compute the $path2process.
|
||||
path2process=$watcher$file
|
||||
path2process=${path2process/$src/$dest}
|
||||
|
||||
# Delete a file or a directory.
|
||||
if [ "$event" == "DELETE" -o "$event" == "DELETE,ISDIR" ]; then
|
||||
|
||||
# If delete a file, use rm -fr, directory, use rmdir for security.
|
||||
if [ "$event" == "DELETE" ]; then
|
||||
rm -fr $path2process
|
||||
else
|
||||
rmdir $path2process
|
||||
fi
|
||||
|
||||
echo `date "+%H:%M:%S"` $path2process deleted.;
|
||||
|
||||
# If event is ngnored, continue.
|
||||
elif [ "$event" == "IGNORED" ]; then
|
||||
|
||||
continue
|
||||
|
||||
# Sync files.
|
||||
else
|
||||
|
||||
echo `date "+%H:%M:%S"` $path2process copied.
|
||||
rsync -aqP --exclude='db/' $src/ $dest
|
||||
fi
|
||||
|
||||
done
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Watch a upload directory and remove dangder files.
|
||||
#
|
||||
# @author chunsheng wang<chunsheng@cnezsoft.com>
|
||||
|
||||
# Judge the params, must give $dir
|
||||
if [ $# -lt 1 ]; then
|
||||
echo './zdog.sh directory'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Judge inotifywait tool exists or not.
|
||||
which inotifywait > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'No inotifywait. Please install inotify-tools, for debian or ubuntun run apt-get install inotify-tools.';
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the directory to watch.
|
||||
dir=$@
|
||||
|
||||
# Watch the $dir directory
|
||||
if [ ! -d "/tmp/zdog" ]; then
|
||||
mkdir -v /tmp/zdog;
|
||||
fi
|
||||
echo `date "+%H:%M:%S"` begin watching $dir > /tmp/zdog/zdog.log
|
||||
inotifywait -mrq --event create,modify --format '%w %e %f' $dir |\
|
||||
while read watcher event file ; do
|
||||
|
||||
# compute the $path2process.
|
||||
path2process=$watcher$file
|
||||
targetfile=/tmp/zdog/$file;
|
||||
echo $path2process | grep -q '.php';
|
||||
if [ $? -eq 0 ] && [ -s $path2process ]; then
|
||||
sudo mv -f $path2process $targetfile;
|
||||
echo `date "+%H:%M:%S"` $path2process moved to $targetfile >> /tmp/zdog/zdog.log 2>&1;
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user