本文整理汇总了PHP中printLog函数的典型用法代码示例。如果您正苦于以下问题:PHP printLog函数的具体用法?PHP printLog怎么用?PHP printLog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printLog函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: errorLog
function errorLog($str)
{
global $logFileHandle, $adminEmail;
printLog($str);
closeLogFile();
exit;
}
开发者ID:lavsurgut,项目名称:autoauc2,代码行数:7,代码来源:cron.php
示例2: run
public function run(array $params)
{
global $f3;
// 1. reset 整个数据库
printLog('Begin Reset Database', 'ResetData');
$dbEngine = DataMapper::getDbEngine();
// 解析 sql 文件,导入数据
$sqlFileContent = file_get_contents(CONSOLE_PATH . '/../install/Asset/data/bzfshop.sql');
$sqlFileContent = SqlHelper::removeComment($sqlFileContent);
$sqlArray = SqlHelper::splitToSqlArray($sqlFileContent, ';');
unset($sqlFileContent);
foreach ($sqlArray as $sqlQuery) {
$queryObject = $dbEngine->prepare($sqlQuery);
$queryObject->execute();
unset($sqlQuery);
unset($queryObject);
}
unset($sqlArray);
printLog('End Reset Database', 'ResetData');
// 2. 删除 /data 目录下的所有目录
printLog('remove everything under /data', 'ResetData');
$this->removeAllDirInsideDir($f3->get('sysConfig[data_path_root]'));
// 3. 删除 RunTime 目录下所有目录
printLog('remove everything in Runtime', 'ResetData');
$this->removeAllDirInsideDir($f3->get('sysConfig[runtime_path]') . DIRECTORY_SEPARATOR . 'Log/');
$this->removeAllDirInsideDir($f3->get('sysConfig[runtime_path]') . DIRECTORY_SEPARATOR . 'Smarty/');
$this->removeAllDirInsideDir($f3->get('sysConfig[runtime_path]') . DIRECTORY_SEPARATOR . 'Temp/');
// 4. 清除 F3 的缓存
$f3->clear('CACHE');
printLog('ResetData Done', 'ResetData');
}
开发者ID:swcug,项目名称:bzfshop,代码行数:31,代码来源:ResetData.php
示例3: updateFieldForTable
/**
* Replace {{skin url=""}} with {{view url=""}} for given table field
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param string $table
* @param string $col
* @return void
*/
function updateFieldForTable($objectManager, $table, $col)
{
/** @var $installer \Magento\Framework\Setup\ModuleDataSetupInterface */
$installer = $objectManager->create('\\Magento\\Framework\\Setup\\ModuleDataSetupInterface');
$installer->startSetup();
$table = $installer->getTable($table);
echo '-----' . "\n";
if ($installer->getConnection()->isTableExists($table)) {
echo 'Table `' . $table . "` processed\n";
$indexList = $installer->getConnection()->getIndexList($table);
$pkField = array_shift($indexList[$installer->getConnection()->getPrimaryKeyName($table)]['fields']);
/** @var $select \Magento\Framework\DB\Select */
$select = $installer->getConnection()->select()->from($table, ['id' => $pkField, 'content' => $col]);
$result = $installer->getConnection()->fetchPairs($select);
echo 'Records count: ' . count($result) . ' in table: `' . $table . "`\n";
$logMessages = [];
foreach ($result as $recordId => $string) {
$content = str_replace('{{skin', '{{view', $string, $count);
if ($count) {
$installer->getConnection()->update($table, [$col => $content], $installer->getConnection()->quoteInto($pkField . '=?', $recordId));
$logMessages['replaced'][] = 'Replaced -- Id: ' . $recordId . ' in table `' . $table . '`';
} else {
$logMessages['skipped'][] = 'Skipped -- Id: ' . $recordId . ' in table `' . $table . '`';
}
}
if (count($result)) {
printLog($logMessages);
}
} else {
echo 'Table `' . $table . "` was not found\n";
}
$installer->endSetup();
echo '-----' . "\n";
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:42,代码来源:themes_view.php
示例4: run
public function run(array $params)
{
$pageSize = 500;
$goodsBasicService = new Goods();
$totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array());
for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) {
// 查询商品
$goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize);
foreach ($goodsArray as $goodsItem) {
$goods_id = $goodsItem['goods_id'];
printLog('begin process goods [' . $goods_id . ']');
$goodsObj = $goodsBasicService->loadGoodsById($goods_id);
if ($goodsObj->isEmpty()) {
printLog('goods [' . $goods_id . '] is empty');
} else {
$goodsObj->goods_desc = str_replace('tuan.bangzhufu.com', 'www.bangzhufu.com', $goodsObj->goods_desc);
$goodsObj->goods_desc = str_replace('cdn.bzfshop.net', 'img.bangzhufu.com', $goodsObj->goods_desc);
$goodsObj->goods_desc = preg_replace('!/Goods/View/goods_id~([0-9]+).html!', '/Goods/View/goods_id-\\1.html', $goodsObj->goods_desc);
$goodsObj->update_time = \Core\Helper\Utility\Time::gmTime();
$goodsObj->save();
}
unset($goodsObj);
printLog('end process goods [' . $goods_id . ']');
}
}
}
开发者ID:swcug,项目名称:bzfshop,代码行数:26,代码来源:FixGoodsInnerLink.php
示例5: verifyNotify
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
*
* @return 验证结果
*/
function verifyNotify()
{
if (empty($_POST)) {
//判断POST来的数组是否为空
return false;
} else {
//生成签名结果
$isSign = $this->getSignVeryfy($_POST, $_POST["sign"]);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'true';
if (!empty($_POST["notify_id"])) {
$responseTxt = $this->getResponse($_POST["notify_id"]);
}
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match("/true\$/i", $responseTxt) && $isSign) {
return true;
}
//失败,写日志记录
if ($isSign) {
$isSignStr = 'true';
} else {
$isSignStr = 'false';
}
$log_text = "Alipay responseTxt=" . $responseTxt . " notify_url_log:isSign=" . $isSignStr . ",";
$log_text = $log_text . createLinkString($_POST);
printLog($log_text, 'PAYMENT', Base::ERROR);
return false;
}
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:36,代码来源:AlipayNotify.php
示例6: printLogL
function printLogL($str, $level)
{
for ($i = 1; $i <= $level; ++$i) {
$str = "\t" . $str;
}
printLog($str);
}
开发者ID:ronando,项目名称:WeBid,代码行数:7,代码来源:functions_cron.php
示例7: getSearchInstance
/**
* 生成搜索的具体 instance
*
* @return ISearch
* @throws \InvalidArgumentException
*/
protected static function getSearchInstance()
{
if (!static::$searchInstance) {
static::$searchInstance = new static::$searchImplementClass();
if (!static::$searchInstance instanceof ISearch) {
throw new \InvalidArgumentException(static::$searchImplementClass . ' is invalid search implement');
}
if (!static::$searchInstance->init(static::$searchImplementInitParamArray)) {
printLog(static::$searchImplementClass . ' init failed with param ' . print_r(static::$searchImplementInitParamArray, true), __CLASS__, \Core\Log\Base::ERROR);
throw new \InvalidArgumentException('can not init ' . static::$searchImplementClass);
}
}
return static::$searchInstance;
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:20,代码来源:SearchHelper.php
示例8: loadTaskClass
/**
* 根据 task_class 参数加载并实例化 Cron 任务对象
*
* @param string $task_class
*
* @return ICronTask 对象
*/
public static function loadTaskClass($task_class)
{
if (!class_exists($task_class)) {
printLog('class [' . $task_class . '] does not exist', __CLASS__, BaseLog::ERROR);
return null;
}
$taskInstance = new $task_class();
if (!is_a($taskInstance, '\\Core\\Cron\\ICronTask')) {
printLog('class [' . $task_class . '] does not implement ICronTask', __CLASS__, BaseLog::ERROR);
unset($taskInstance);
return null;
}
return $taskInstance;
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:21,代码来源:CronHelper.php
示例9: addAutoloadPath
/**
* 添加一个用于 class autoload 的路径
*
* 注意:我们允许 plugin 覆盖系统本身的功能,所以如果你的 path 里面包含和系统名字一样的 Controller,
* 你就可能会覆盖系统已有的操作
*
* @param string $path
* @param bool $addToHead 是否加入搜索路径的开头,如果你的类不常用,请加入到搜索末尾有利于提高搜索效率
*
*/
public static function addAutoloadPath($path, $addToHead = false)
{
if (!file_exists($path)) {
printLog('[' . $path . '] does not exist', 'SystemHelper', \Core\Log\Base::WARN);
return;
}
$path = realpath($path);
global $f3;
if ($addToHead) {
// 加到搜索路径开头
$f3->set('AUTOLOAD', $path . '/;' . $f3->get('AUTOLOAD'));
} else {
// 加到搜索路径末尾
$f3->set('AUTOLOAD', $f3->get('AUTOLOAD') . $path . '/;');
}
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:26,代码来源:SystemHelper.php
示例10: __callstatic
/**
* 调用对应的对象方法
*
* @param $func
* @param array $args
*
* @return mixed
* @throws \InvalidArgumentException
*/
static function __callstatic($func, array $args)
{
foreach (static::$registerClassArray as $className => $initParam) {
$instance = static::loadClassInstance($className, $initParam);
// 检查方法是否存在
if (!method_exists($instance, $func)) {
throw new \InvalidArgumentException('class [' . $className . '] has no method [' . $func . ']');
}
global $f3;
if ($f3->get('DEBUG') > 2) {
printLog('call [' . $className . '] method [' . $func . ']', __CLASS__, \Core\Log\Base::DEBUG);
}
// 调用对象方法
call_user_func_array(array($instance, $func), $args);
// 释放内存
unset($instance);
}
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:27,代码来源:PipelineHelper.php
示例11: loadModule
private function loadModule($searchType)
{
// 检查对应的搜索模块是否存在
$filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $searchType . '.php';
if (!file_exists($filePath)) {
// 没有对应的搜索模块,失败
printLog($searchType . ' does not exist', __CLASS__, \Core\Log\Base::ERROR);
return false;
}
require_once $filePath;
// 生成搜索模块
$searchType = __NAMESPACE__ . '\\' . $searchType;
$searchModule = new $searchType();
if (!$searchModule || !$searchModule instanceof ISearch) {
throw new \InvalidArgumentException($searchType . ' is an invalid ISearch');
}
return $searchModule;
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:18,代码来源:SqlSearch.php
示例12: run
public function run(array $params)
{
global $f3;
// 每次处理多少条记录
$batchProcessCount = 100;
// 图片所在的根目录
$dataPathRoot = $f3->get('sysConfig[data_path_root]');
$image_thumb_width = $f3->get('sysConfig[image_thumb_width]');
$image_thumb_height = $f3->get('sysConfig[image_thumb_height]');
$goodsGalleryService = new GoodsGalleryService();
$baseService = new BaseService();
$totalGoodsGalleryCount = $baseService->_countArray('goods_gallery', null);
// 记录处理开始
for ($offset = 0; $offset < $totalGoodsGalleryCount; $offset += $batchProcessCount) {
$goodsGalleryArray = $baseService->_fetchArray('goods_gallery', '*', null, array('order' => 'img_id asc'), $offset, $batchProcessCount);
foreach ($goodsGalleryArray as $goodsGalleryItem) {
if (!is_file($dataPathRoot . '/' . $goodsGalleryItem['img_original'])) {
continue;
// 文件不存在,不处理
}
$pathInfoArray = pathinfo($goodsGalleryItem['img_original']);
//生成缩略图
$imageThumbFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $image_thumb_width . 'x' . $image_thumb_height . '.jpg';
//重新生存缩略图
printLog('Re-generate File :' . $imageThumbFileRelativeName);
StorageImageHelper::resizeImage($dataPathRoot, $goodsGalleryItem['img_original'], $imageThumbFileRelativeName, $image_thumb_width, $image_thumb_height);
// 更新 goods_gallery 设置
printLog('update goods_gallery img_id [' . $goodsGalleryItem['img_id'] . ']');
$goodsGallery = $goodsGalleryService->loadGoodsGalleryById($goodsGalleryItem['img_id']);
if (!$goodsGallery->isEmpty()) {
$goodsGallery->thumb_url = $imageThumbFileRelativeName;
$goodsGallery->save();
}
// 主动释放资源
unset($goodsGallery);
unset($pathInfoArray);
unset($imageThumbFileRelativeName);
}
unset($goodsGalleryArray);
printLog('re-generate thumb image offset : ' . $offset);
}
printLog('re-generate thumb image finished , offset : ' . $offset);
}
开发者ID:swcug,项目名称:bzfshop,代码行数:43,代码来源:RegenerateThumbImage.php
示例13: SelectValue
public static function SelectValue($retrieveValue, $tablename, $conditions)
{
$mydb = self::getFactory()->getConnection();
$values = array();
$condclauses = array();
foreach ($conditions as $key => $value) {
$condclauses[] = $key . "=?";
$values[] = $value;
}
$stmtString = "SELECT " . $retrieveValue . " FROM " . $tablename . " WHERE ";
$stmtString .= getArrayInString($condclauses, 'and');
$stmt = $mydb->prepare($stmtString);
$start = microtime(true);
$stmt->execute($values);
$time = microtime(true) - $start;
self::$log[] = array('query' => $stmt->queryString, 'time' => round($time * 1000, 3));
return $stmt->fetchColumn();
printLog();
}
开发者ID:ng2k12,项目名称:MercInc,代码行数:19,代码来源:ConnectionFactory.php
示例14: run
public function run(array $params)
{
printLog('Begin CreateDictionary', 'CreateDictionary');
$metaDictionaryService = new MetaDictionaryService();
// 用于 order_refer 中显示订单来源渠道 utm_source
$metaDictionaryService->saveWord('SELF', '网站自身', '网站自身', '');
$metaDictionaryService->saveWord('TUAN360CPS', '360团购导航', '360团购导航', '');
$metaDictionaryService->saveWord('YIQIFACPS', '亿起发', '亿起发', '');
$metaDictionaryService->saveWord('DUOMAICPS', '多麦', '多麦', '');
// 用于 order_refer 中显示订单来源渠道 utm_medium
$metaDictionaryService->saveWord('QQCAIBEI', 'QQ彩贝', 'QQ彩贝', '');
$metaDictionaryService->saveWord('TUAN360TEQUAN', '360特权', '360特权', '');
$metaDictionaryService->saveWord('TUAN360WAP', '360手机WAP', '360手机WAP', '');
// 用于 order_refer 中显示订单登陆方式 login_type
$metaDictionaryService->saveWord('normal', '普通登陆', '普通登陆', '');
$metaDictionaryService->saveWord('qqcaibei', 'QQ彩贝登陆', 'QQ彩贝登陆', '');
$metaDictionaryService->saveWord('qqlogin', 'QQ登陆', 'QQ登陆', '');
$metaDictionaryService->saveWord('tuan360auth', '360联合登陆', '360联合登陆', '');
printLog('Finish CreateDictionary', 'CreateDictionary');
}
开发者ID:swcug,项目名称:bzfshop,代码行数:20,代码来源:CreateDictionary.php
示例15: run
public function run(array $params)
{
global $f3;
// 每次处理多少条记录
$batchProcessCount = 100;
$baseService = new BaseService();
$totalGoodsCount = $baseService->_countArray('goods', null);
// 记录处理开始
for ($offset = 0; $offset < $totalGoodsCount; $offset += $batchProcessCount) {
$goodsArray = $baseService->_fetchArray('goods', 'goods_id', null, array('order' => 'goods_id asc'), $offset, $batchProcessCount);
foreach ($goodsArray as $goodsItem) {
$sql = "update " . DataMapper::tableName('goods') . ' set ' . ' user_buy_number = (select sum(goods_number) from ' . DataMapper::tableName('order_goods') . ' where goods_id = ? )' . ' ,user_pay_number = (select sum(goods_number) from ' . DataMapper::tableName('order_goods') . ' where goods_id = ? and order_goods_status > 0)' . ' where goods_id = ? order by goods_id asc limit 1 ';
$dbEngine = DataMapper::getDbEngine();
$dbEngine->exec($sql, array(1 => $goodsItem['goods_id'], $goodsItem['goods_id'], $goodsItem['goods_id']));
}
unset($goodsArray);
printLog('calculate goods buy number offset : ' . $offset);
}
printLog('calculate goods buy number finished , offset : ' . $offset);
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:20,代码来源:CalculateGoodsBuyNumber.php
示例16: run
public function run(array $params)
{
global $f3;
$outputFile = $f3->get('TEMP') . 'CheckGoodsInnerImageUrl.log';
$imageHostAllow = array('img.bangzhufu.com');
$pageSize = 500;
$goodsBasicService = new Goods();
$totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array());
for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) {
// 查询商品
$goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize);
foreach ($goodsArray as $goodsItem) {
$goods_id = $goodsItem['goods_id'];
printLog('begin process goods [' . $goods_id . ']');
$goodsObj = $goodsBasicService->loadGoodsById($goods_id);
if ($goodsObj->isEmpty()) {
printLog('goods [' . $goods_id . '] is empty');
} else {
$patternMatch = array();
preg_match_all('/<img(.*?)src="(.*?)"(.*?)\\/?>/', $goodsObj->goods_desc, $patternMatch, PREG_SET_ORDER);
$isFirst = true;
// 处理每一个图片
foreach ($patternMatch as $matchItem) {
$imageUrl = $matchItem[2];
$urlInfo = parse_url($imageUrl);
if (!in_array(@$urlInfo['host'], $imageHostAllow)) {
if ($isFirst) {
$isFirst = false;
$f3->write($outputFile, "\n\ngoods_id:" . $goodsObj->goods_id . "\n", true);
}
$f3->write($outputFile, "\t" . $matchItem[2] . "\n", true);
printLog('illegal image url [' . $matchItem[2] . ']');
}
}
unset($patternMatch);
}
unset($goodsObj);
printLog('end process goods [' . $goods_id . ']');
}
}
}
开发者ID:swcug,项目名称:bzfshop,代码行数:41,代码来源:CheckGoodsInnerImageUrl.php
示例17: Run
/**
* 驱动 Cron 任务执行
*
* @param $f3
*/
public function Run($f3)
{
$taskCount = 0;
while (($cronTask = CronHelper::loadNextUnRunCronTask(Time::gmTime())) && $taskCount++ < self::$maxRunTaskCount) {
$cronResult = array('code' => -1, 'message' => '任务内部错误,请查看日志');
// 加载 Task Class
$taskInstance = CronHelper::loadTaskClass($cronTask['task_class']);
// 无法实例化 task class,打印错误日志
if (null == $taskInstance) {
printLog('can not instantiate task ' . json_encode($cronTask->toArray()), __CLASS__, \Core\Log\Base::ERROR);
} else {
// 执行任务
$cronResult = call_user_func_array(array($taskInstance, 'run'), array(json_decode($cronTask['task_param'], true)));
}
// 释放内存
unset($taskInstance);
// 更新任务执行状态
$cronTask->task_run_time = Time::gmTime();
$cronTask->return_code = @$cronResult['code'];
$cronTask->return_message = @$cronResult['message'];
$cronTask->save();
unset($cronTask);
}
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:29,代码来源:CronController.php
示例18: doReturnUrl
public function doReturnUrl($f3)
{
printLog('CreditPay returnUrl success', 'PAYMENT', Base::INFO);
// 设置 order_id
$this->orderId = $f3->get('GET[order_id]');
return true;
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:7,代码来源:CreditGateway.php
示例19: post
public function post($f3)
{
//首先验证参数签名
$map = $_POST;
unset($map['Vkey']);
//读取除了vkey外的所有参数,并且放入数组map中
ksort($map);
//进行按参数的升序排序
//进行签名,注意考虑到md5加密输出的大小写问题,所有约定md5的输出均为小写
$vkey = implode('', array_values($map));
$md5_1 = strtolower(md5($vkey . YiqifaCpsPlugin::getOptionValue('qqcaibei_key1')));
$vkey = strtolower(md5($md5_1 . YiqifaCpsPlugin::getOptionValue('qqcaibei_key2')));
if ($vkey != $_POST['Vkey']) {
// 参数签名错误
goto out;
}
// 保存额外的 亿起发 参数
$orderRefer = array();
$orderRefer['utm_medium'] = 'QQCAIBEI';
//设置 cookie
ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration'));
$f3->set('SESSION[yiqifa_caibei_order_refer]', ReferHelper::parseOrderRefer($f3));
// 取得QQ彩贝传递过来的参数
//$acct = @$_POST['Acct'];
$url = @$_POST['Url'];
$openId = @$_POST['OpenId'];
//$clubInfo = @intval($_POST['ClubInfo']); // 会员等级信息,目前没用
$viewInfo = @$_POST['ViewInfo'];
if (get_magic_quotes_gpc()) {
$viewInfo = stripslashes($viewInfo);
}
$viewInfoArray = array();
parse_str($viewInfo, $viewInfoArray);
//解析 viewInfoArray 数组
//$f3->set('SESSION[qqcaibei_viewinfoarray]', json_encode($viewInfoArray)); //放入到 session 里面
// 设置 ClientData
ClientData::saveClientData('qqcaibei_viewinfoarray', json_encode($viewInfoArray));
if (empty($openId)) {
// 没有 openId 没法登陆,直接退出
goto out;
}
// 这里做 QQ彩贝 联合登陆
$sns_login = "qq:{$openId}";
// 用户登陆操作
$userBasicService = new UserBasicService();
$authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
if ($authUser) {
goto out_login_user;
}
// 之前没有登陆过,自动注册用户
$authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
printLog('注册QQ用户:' . print_r($viewInfoArray, true), 'QQLOGIN', \Core\Log\Base::INFO);
out_login_user:
AuthHelper::saveAuthUser($authUser->toArray(), 'qqcaibei');
// 设置用户名在网页显示
ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ彩贝用户:' . $viewInfoArray['NickName']);
out:
// 页面跳转到商品
$redirectUrl = empty($url) ? '/' : $url;
RouteHelper::reRoute($this, $redirectUrl);
return;
}
开发者ID:jackycgq,项目名称:bzfshop,代码行数:63,代码来源:CaibeiLogin.php
示例20: convertTable
/**
* 把一个表的数据转换到另外一个表中
*
* @param string $srcTableName 源表名
* @param array $condArray
* array(
* array('supplier_id = ?', $supplier_id)
* array('is_on_sale = ?', 1)
* array('supplier_price > ? or supplier_price < ?', $priceMin, $priceMax)
* )
* @param array $optionArray 排序分页等条件 ,格式例如 array('order' => 'goods_id asc', 'offset' => 100, 'limit' => '10')
* @param string $dstTableName 目的表名
* @param array $columnMap 列对应,格式如 array('id' => 'goods_id' , 'name' => 'goods_name')
* @param array $srcValueConvertFuncArray
* 对源数据做装换,例如: array('id' => function($srcValue, $srcRecord){ return $srcValue + 1;} , ...),用闭包函数做转化
* @param callable $recordPreFunc 在查询到 src 的记录之后调用 ,函数原型 function(&$srcRecord){ ... }
* @param callable $recordPostFunc 在 src 已经往 dst 赋值完成之后,dst 还没有写入数据库之前调用,函数原型 function(&$srcRecord, &dstRecord){...}
*
*/
public function convertTable($srcTableName, $condArray, $optionArray, $dstTableName, $columnMap, $srcValueConvertFuncArray, $recordPreFunc = null, $recordPostFunc = null)
{
$srcFieldArray = array();
$dstFieldArray = array();
foreach ($columnMap as $srcField => $dstField) {
$srcFieldArray[] = $srcField;
$dstFieldArray[] = $dstField;
}
$srcTable = new SrcDataMapper($srcTableName);
// 构造查询条件
$filter = null;
if (!empty($condArray)) {
$filter = QueryBuilder::buildAndFilter($condArray);
}
// 获得总数
$totalRecordCount = $srcTable->count($filter);
printLog('begin convertTable ' . $srcTableName . '-->' . $dstTableName . ' totalRecordCount:' . $totalRecordCount, self::$loggerSource);
$recordLeft = $totalRecordCount;
// 剩余多少记录需要处理
$queryOffset = 0;
// 查询的起始位置
while ($recordLeft > 0) {
// 这次需要处理多少记录
$processCount = $recordLeft > $this->batchProcessCount ? $this->batchProcessCount : $recordLeft;
// 记录处理进度
printLog('totalRecordCount:' . $totalRecordCount . ' recordLeft:' . $recordLeft . ' processCount:' . $processCount, self::$loggerSource);
$recordLeft -= $processCount;
// 从源表查询数据
$srcField = '*';
if (!empty($srcFieldArray)) {
$srcField = implode(',', $srcFieldArray);
}
// 处理查询的起始位置
$optionArray = array_merge($optionArray, array('offset' => $queryOffset, 'limit' => $processCount));
$queryOffset += $processCount;
// 查询数据
$srcRecordList = $srcTable->select($srcField, $filter, $optionArray);
// 转换数据到目标表中
foreach ($srcRecordList as $srcRecordItem) {
// PreFunc 处理
if ($recordPreFunc) {
$recordPreFunc($srcRecordItem);
}
$dstTable = new DstDataMapper($dstTableName);
//字段复制
foreach ($columnMap as $srcField => $dstField) {
// 无意义的字段,不复制
if (null == $dstField) {
continue;
}
if (isset($srcValueConvertFuncArray) && isset($srcValueConvertFuncArray[$srcField])) {
if (!is_callable($srcValueConvertFuncArray[$srcField])) {
printLog($srcField . ' value convert is not function ', self::$loggerSource, \Core\Log\Base::ERROR);
continue;
}
// 做数据转化
$dstTable->{$dstField} = $srcValueConvertFuncArray[$srcField]($srcRecordItem[$srcField], $srcRecordItem);
} else {
$dstTable->{$dstField} = $srcRecordItem[$srcField];
}
}
// postFunc 处理
if ($recordPostFunc) {
$recordPostFunc($srcRecordItem, $dstTable);
}
$dstTable->save();
unset($dstTable);
// 及时释放数据,优化内存使用
}
unset($srcRecordList);
// 及时释放数据,优化内存使用
gc_collect_cycles();
// 主动做一次垃圾回收
}
printLog('finish convertTable ' . $srcTableName . '-->' . $dstTableName . ' totalRecordCount:' . $totalRecordCount, self::$loggerSource);
}
开发者ID:swcug,项目名称:bzfshop,代码行数:95,代码来源:TableMigrate.php
注:本文中的printLog函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论