Beispiel #1
0
 public function db()
 {
     if ($this->db == null) {
         $this->db = WF_Registry::get('db');
     }
     return $this->db;
 }
Beispiel #2
0
 public function __construct($db_config = null)
 {
     if (is_array($db_config) && (isset($db_config['host']) || isset($db_config['dsn']))) {
         if (!isset($db_config['dsn'])) {
             if (!isset($db_config['adapter'])) {
                 $this->adapter = 'mysql';
             }
             $dsn = $this->adapter . ":host=" . $db_config['host'] . ";port=" . $db_config['port'];
             if (isset($db_config['dbname'])) {
                 $dsn .= ";dbname=" . $db_config['dbname'];
             }
             $options = array();
             if ($this->adapter == 'mysql') {
                 $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $db_config['enCode']);
             }
             $this->connect($dsn, $db_config['username'], $db_config['password'], $options);
         } else {
             $this->connect($db_config['dsn'], $db_config['username'], $db_config['password'], array());
         }
     } elseif (is_string($db_config)) {
         $dsn = $db_config;
         $username = '';
         $password = '';
         $this->connect($dsn, $username, $password);
     }
     $this->logger = WF_Registry::get('logger');
 }
Beispiel #3
0
 public function init()
 {
     parent::init();
     $vars = get_object_vars($this->CData->CDb);
     $keys = array_keys($vars);
     $logger = new WF_Logger($this->CLog);
     WF_Registry::set('logger', $logger);
 }
Beispiel #4
0
 public function __construct()
 {
     $this->prj = new Tags_project('tcms.interface.tags');
     WF_Registry::set('db', $this->prj->CData->CDb->r);
     $this->tagsController = $this->prj->rs->data->ext['tags'];
     $redis = WF_Registry::get('redis');
     $redis->flushAll();
 }
Beispiel #5
0
 public function __construct()
 {
     parent::__construct();
     $this->server = 'http://i.interface.webdev.com';
     $this->prj = new Tags_project('tcms.interface.tags');
     WF_Registry::set('db', $this->prj->CData->CDb->r);
     $_SERVER['http_proxy'] = '';
 }
Beispiel #6
0
 public static function fire($name, $data = array())
 {
     $event = new WF_Event($name, $data);
     if (isset(self::$handlers[$name])) {
         foreach (self::$handlers[$name] as $callback) {
             try {
                 call_user_func($callback, $event);
             } catch (Exception $e) {
                 $logger = WF_Registry::get('logger');
                 if ($logger) {
                     $logger->warn("call " . WF_Util::getFuncName($callback) . " failed\n");
                 }
             }
         }
     }
 }
Beispiel #7
0
 public function query($sql, $params = array())
 {
     $logger = WF_Registry::get('logger');
     $logger->debug("sql query result: '{$sql} (" . implode(', ', $params) . ")' rowset count:");
     if (!$this->conn) {
         return false;
     }
     $stmt = $this->conn->prepare($sql);
     if (!$stmt) {
         $logger->error("sql prepare failed '{$sql}'");
         $logger->error("db error:" . $this->conn->errorCode() . ' ' . json_encode($this->conn->errorInfo()));
         return false;
     }
     $result = $stmt->execute($params);
     if (!$result) {
         $logger->error("sql query failed '{$sql} (" . implode(', ', $params) . ")'");
         $logger->error("db error:" . $stmt->errorCode() . ' ' . json_encode($stmt->errorInfo()));
     }
     return $stmt;
 }
Beispiel #8
0
$query = 'io_' . $method;
$site = $query('site');
$news_id = $query('news_id');
$title = trim($query('title'));
$abstract = trim($query('abstract'));
$pub_time = $query('pub_time');
$thumbnail = $query('thumbnail');
$errors = array(10 => 'Invalid Arguments', 50 => 'Add article failed');
try {
    if (empty($site) || empty($news_id) || empty($title) || empty($pub_time)) {
        _log("params error in addArticle site:{$site}, {$news_id}, {$news_id}, title:{$title}", "ERROR");
        throw new CmsInterfaceException(10);
    }
    $controller = $prj->rs->data->ext['tags'];
    $db = $prj->CData->CDb->w;
    WF_Registry::set('db', $db);
    $title = project_convert_input($prj, $title);
    $abstract = project_convert_input($prj, strval($abstract));
    $result = $controller->addArticle($site, $news_id, $title, $pub_time, $abstract, $thumbnail);
    if ($result === false) {
        throw new CmsInterfaceException(50);
    }
    $cost = microtime(true) - $profile_begin;
    $prj->fw->interface->out(0, 'success', $cost, $result);
} catch (CmsInterfaceException $e) {
    project_output_error($prj, $e, $errors);
} catch (Exception $e) {
    $this->fw->interface->out($e->getCode(), $e->getMessage(), '', '');
}
function _log($msg, $level = 'ERROR')
{
Beispiel #9
0
<?php

// change the following paths if necessary
require_once 'inc/tags/lib/Loader.class.php';
WF_Loader::registerAutoload();
require_once "inc/tags/TagArticles.inc.php";
require_once "inc/tags/Tag.inc.php";
require_once "inc/tags/ArticleTags.inc.php";
require_once "inc/tags/ArticleMini.inc.php";
require_once "inc/tags/TagsKey.inc.php";
require_once "inc/tags/TagSite.inc.php";
require __DIR__ . '/fixtures/util.func.php';
$conf = (require __DIR__ . '/config/test.conf.php');
define("ROOT_DIR", __DIR__);
WF_Registry::set('logger', new WF_Logger());
$instance = WF_Db::instance($conf['db']);
WF_Registry::set('db', $instance);
unset($instance);
WF_DbTestCase::setBasePath(ROOT_DIR . "/fixtures");
WF_Event::bind('addArticleTag', array(TagArticles::model(), 'onAddArticleTag'));
WF_Event::bind('removeArticleTag', array(TagArticles::model(), 'onRemoveArticleTag'));
$redis = new Redis();
$redis_config = $conf['redis'];
$redis->connect($redis_config['host'], $redis_config['port']);
$redis->flushAll();
WF_Registry::set('cache', $redis);
WF_Registry::set('redis', $redis);
WF_Config::set('tagitem_use_cache', true);
TagSite::refresh(__DIR__ . '/data/sites.dat');
$id = TagSite::getSiteId('news');
Beispiel #10
0
 function __construct($project)
 {
     $this->cache = $project->CData->CCache;
     $this->logger = WF_Registry::get('logger');
 }
Beispiel #11
0
 public function tableName()
 {
     $prefix = WF_Registry::get('prefix', 'tbl_');
     return $prefix . "article_tags";
 }
 protected function getDb()
 {
     if ($this->db == null) {
         $this->db = WF_Registry::get('db');
     }
     return $this->db;
 }
Beispiel #13
0
 public function getLogger()
 {
     if ($this->logger) {
         return $this->logger;
     }
     return WF_Registry::get('logger');
 }