getSchools(); foreach ($schools as $school) { echo 'start' . $school['school_id'] . ' ' . $school['school_name'] . PHP_EOL; $con = $this->getSchoolDbCon($school['school_id']); if (!$con) { echo 'school database cannot connect' . PHP_EOL; continue; } try { //self::updateIspVersion($con); self::initTemplate3($con); echo $school['school_name'] . 'done' . PHP_EOL; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; continue; } sleep(0.1); } echo 'end 处理完成' . PHP_EOL; exit; } /** * 获取所有正常可用的学校 * @return mixed */ private function getSchools() { $db = Yii::app()->businessDb; $sql = "SELECT school_id,school_name FROM `school` WHERE `status`=0 AND `section`=0"; $schools = $db->createCommand($sql)->queryAll(); $db->close(); return $schools; } /** * 学校库连接 * @param $schoolId * @return bool|CDbConnection */ public function getSchoolDbCon($schoolId) { $db = BusinessDatabase::model()->find('school_id=:sid', array(':sid' => $schoolId)); if (empty($db)) { return false; } $myDbDsn = 'mysql:host=' . $db->database_host . ';dbname=' . $db->database_name; $my_connection = new CDbConnection($myDbDsn, $db->database_user, $db->database_password); $my_connection->emulatePrepare = true; $my_connection->enableProfiling = true; $my_connection->enableParamLogging = true; $myDbDsn = null; return $my_connection; } /** * 初始化3.0模板数据 * @param $con */ private function initTemplate3($con) { //查询是否有默认模板 $wrongBook = array(); $isp = array(); $templates = $con->createCommand("select template_id,template_name,product_type,subject_id,target_type,is_default from product_template where is_beta=0 and is_default=1 and subject_id = 41")->queryAll(); //判断默认模板是否存在 $wrongBookClassConfig = <<createCommand($sql)->execute(); } } }