/**
  * 重置链接信息
  *
  * @param string $db        	
  * @return void
  */
 private function _resetConnection($db)
 {
     $_config = $this->getConfig($db);
     if (!$_config) {
         throw new WindDbException('[db.WindConnectionManager._initConfig] db connection ' . $db . ' is not exist.');
     }
     parent::_initConfig($_config);
 }
Exemplo n.º 2
0
 /**
  * 导入默认数据
  */
 public function dataAction()
 {
     @set_time_limit(300);
     $db = $this->_checkDatabase();
     try {
         $pdo = new WindConnection($db['dsn'], $db['user'], $db['pwd']);
         $pdo->setConfig($db);
     } catch (PDOException $e) {
         $this->showError($e->getMessage(), false);
     }
     $tableSql = (include $this->_getTableSqlFile());
     try {
         foreach ($tableSql['UPDATE'] as $sql) {
             $pdo->query($sql);
         }
     } catch (PDOException $e) {
         $this->showError($e->getMessage(), false);
     }
     $pdo->close();
     //数据库配置
     $database = array('dsn' => $db['dsn'], 'user' => $db['user'], 'pwd' => $db['pwd'], 'charset' => $db['charset'], 'tableprefix' => $db['tableprefix'], 'engine' => $db['engine']);
     WindFile::savePhpData($this->_getDatabaseFile(), $database);
     //写入windid配置信息
     $this->_writeWindid();
     $this->forwardRedirect(WindUrlHelper::createUrl('index/finish'));
 }
 /**
  * 升级账号通的数据
  */
 public function upgrade()
 {
     Wind::import("WIND:db.WindConnection");
     $configFile = (include Wind::getRealPath($this->upgradeConfig));
     $dsn = 'mysql:dbname=' . $configFile['old_db_name'] . ';host=' . $configFile['old_db_host'] . ';port=' . $configFile['old_db_port'];
     $siteId = $configFile['siteId'];
     $siteHash = $configFile['siteHash'];
     $appsUrl = 'http://apps.phpwind.com/upgradeweiboapi.php';
     //分页
     $limit = $configFile['limit'];
     //每次升级200个
     $page = $_GET['page'];
     $page = $page < 1 ? 1 : intval($page);
     list($offset, $limit) = Pw::page2limit($page, $limit);
     $sql = "SELECT * FROM pw_weibo_bind WHERE weibotype = '{$this->type}' LIMIT " . max(0, intval($offset)) . " , " . max(1, intval($limit));
     try {
         $pdo = new WindConnection($dsn, $configFile['old_db_user'], $configFile['old_db_pass']);
         $result = $pdo->query($sql)->fetchAll();
     } catch (PDOException $e) {
         $error = $e->getMessage();
         return new PwError($error);
     }
     if (empty($result)) {
         return true;
     }
     $bbsUids = array();
     $bind = array();
     foreach ($result as $key => $value) {
         $bbs_uid = intval($value['uid']);
         if ($bbs_uid) {
             $bbsUids[] = intval($bbs_uid);
         }
     }
     $uids = implode($bbsUids, ',');
     $param = array('uids' => $uids, 'site_id' => $siteId, 'type' => $this->type);
     ksort($param);
     $checkSign = md5(http_build_query($param) . $siteHash);
     $url = $appsUrl . '?uids=' . $uids . '&siteid=' . $siteId . '&type=' . $this->type . '&sign=' . $checkSign;
     $response = $this->request($url);
     unset($param, $checkSign, $url);
     $info = json_decode($response, TRUE);
     if ($info[0] === false) {
         return new PwError('接口通信失败');
     }
     $info = $info[1];
     $dm = new App_Account_QzoneUserInfoDm();
     foreach ($bbsUids as $key => $value) {
         if ($info[$value]) {
             $qqInfo = $this->_getQzoneUserInfoDs()->getByOpenId($info[$value]);
             if ($qqInfo) {
                 $user_id = $qqInfo['user_id'];
             } else {
                 $dm->setOpenId($info[$value])->setCreateAt(Pw::getTime());
                 $user_id = $this->_getQzoneUserInfoDs()->add($dm);
             }
             $bind[] = array('uid' => $value, 'type' => $this->type, 'app_uid' => $user_id);
         }
     }
     $this->_getAccountBindDs()->batchAdd($bind);
     unset($bind, $bbsUids);
     return $page + 1;
 }
Exemplo n.º 4
0
 /**
  * 升级数据
  */
 public function upgrade()
 {
     Wind::import("WIND:db.WindConnection");
     $configFile = (include Wind::getRealPath($this->upgradeConfig));
     $dsn = 'mysql:dbname=' . $configFile['old_db_name'] . ';host=' . $configFile['old_db_host'] . ';port=' . $configFile['old_db_port'];
     //分页
     $limit = $configFile['limit'];
     //每次升级200个
     $page = $_GET['page'];
     $page = $page < 1 ? 1 : intval($page);
     list($offset, $limit) = Pw::page2limit($page, $limit);
     $sql = "SELECT * FROM pw_weibo_bind WHERE weibotype = '{$this->type}' LIMIT " . max(0, intval($offset)) . " , " . max(1, intval($limit));
     try {
         $pdo = new WindConnection($dsn, $configFile['old_db_user'], $configFile['old_db_pass']);
         $result = $pdo->query($sql)->fetchAll();
     } catch (PDOException $e) {
         $error = $e->getMessage();
         return new PwError($error);
     }
     //升级完成
     if (empty($result)) {
         return true;
     }
     $bindInfo = array();
     foreach ($result as $key => $value) {
         //解决反序列化字符串编码不一致问题
         $unserialized = $value['info'];
         $unserialized = preg_replace('!s:(\\d+):"(.*?)";!se', "'s:'.strlen('\$2').':\"\$2\";'", $unserialized);
         $info = unserialize($unserialized);
         if ($value['uid'] && $info['id']) {
             $bindInfo[] = array('uid' => intval($value['uid']), 'type' => $this->type, 'app_uid' => intval($info['id']));
         }
     }
     $this->_getAccountBindDs()->batchAdd($bindInfo);
     return $page + 1;
 }