Пример #1
0
 /**
  * @test
  */
 public function canUpdateAnEntity()
 {
     $expectedConditions = array('id' => 1);
     $expectedParams = array('id' => 1, 'name' => 'foo', 'value' => 'bar');
     $this->storage->expects($this->once())->method('updateWhere')->with($expectedConditions, $expectedParams)->will($this->returnValue(1));
     $entity = $this->createEntity();
     $entity->setId(1);
     $this->repository->persist($entity);
 }
Пример #2
0
 private function getArticle($article_id)
 {
     $params = array();
     $params = array('eq' => array('article_id' => $article_id));
     if (!$this->is_root) {
         $params['lt'] = array('category_id' => 5);
     }
     $article = Repository::findOneFromArticle($params);
     if ($article == false) {
         header("Location: /index/notfound");
         return;
     }
     $params['tags'] = SqlRepository::getTags($article_id);
     $params['title'] = $article->get_title();
     $params['indexs'] = json_decode($article->get_indexs());
     $params['contents'] = \TechlogTools::pre_treat_article($article->get_draft());
     $params['title_desc'] = $article->get_title_desc();
     $params['article_category_id'] = $article->get_category_id();
     if (StringOpt::spider_string($params['contents'], '"page-header"', '</div>') === null) {
         $params['contents'] = '<div class="page-header"><h1>' . $article->get_title() . '</h1></div>' . $params['contents'];
     }
     $article->set_access_count($article->get_access_count() + 1);
     Repository::persist($article);
     $params['inserttime'] = $article->get_inserttime() . '&nbsp;&nbsp;&nbsp;最后更新: ' . $article->get_updatetime() . '&nbsp;&nbsp;&nbsp;访问数量:' . ($article->get_access_count() + 1);
     return $params;
 }
Пример #3
0
 public function record_access()
 {
     $remote_host = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '-';
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '-';
     $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '-';
     $stats = new StatsModel(array('time_str' => 'now()', 'remote_host' => $remote_host, 'request' => "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'referer' => $referer, 'user_agent' => $user_agent));
     Repository::persist($stats);
 }
Пример #4
0
}
$month = $options['m'];
$income = (double) $options['i'];
$expend = (double) $options['e'];
$image_id = (int) $options['a'];
$sql = 'select path from images where image_id = ' . $image_id;
$path = Repository::findPathFromImages(array('eq' => array('image_id' => $image_id)));
if ($path == false) {
    LogOpt::set('exception', 'image_not_exists');
    return false;
}
$article = new ArticleModel(array('title' => $month . '财报', 'updatetime' => 'now()', 'inserttime' => 'now()', 'draft' => '<div>' . PHP_EOL . '<!-- 图片大小:700*467 -->' . PHP_EOL . '</div>', 'category_id' => 6));
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'new_note_insert_into_article_error');
    return false;
}
LogOpt::set('info', 'new_note_insert_into_article_success', 'article_id', $article_id);
$infos = array();
$infos['article_id'] = $article_id;
$infos['image_id'] = $image_id;
$infos['month'] = $month;
$infos['income'] = $income;
$infos['expend'] = $expend;
$earnings = new EarningsModel(array('article_id' => $article_id, 'image_id' => $image_id, 'month' => $month, 'income' => $income, 'expend' => $expend, 'inserttime' => 'now()'));
$earnings_id = Repository::persist($earnings);
if ($earnings_id == false) {
    LogOpt::set('exception', 'new_earnings_insert_into_booknote_error');
    return false;
}
LogOpt::set('info', 'new_earnings_insert_into_booknote_success', 'earnings_id', $earnings_id);
Пример #5
0
        }
        $image_path = trim($image_path);
        if (!file_exists(WEB_PATH . '/resource/' . $image_path)) {
            LogOpt::set('exception', '文中目标图片不存在', 'image_path', $image_path);
            return;
        }
        $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
        if ($image_id == false) {
            $full_path = WEB_PATH . '/resource/' . $image_path;
            $image_id = TechlogTools::load_image($full_path, 'article');
            if ($image_id == false) {
                LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
                return;
            }
            LogOpt::set('info', '添加图片到数据库成功', 'image_id', $image_id, 'image_path', $image_path);
            $image_ids[] = $image_id;
        }
    }
    $article = Repository::findOneFromArticle(array('eq' => array('article_id' => $article_id)));
    foreach ($infos as $key => $value) {
        $func = 'set_' . $key;
        $article->{$func}($value);
    }
    $ret = Repository::persist($article);
    if ($ret == false) {
        LogOpt::set('exception', 'article 更新失败', 'article_id', $article_id);
        return;
    }
    LogOpt::set('info', 'article 更新成功', 'article_id', $ret);
    unlink($draft_file);
}
Пример #6
0
 public static function load_image($path, $category = '')
 {
     $file_path = self::getfilepath($path);
     if (!file_exists($file_path)) {
         echo $file_path . PHP_EOL;
         return false;
     }
     $pos = strpos($file_path, '/html/');
     if ($pos === false) {
         return false;
     }
     $image = new ImagesModel(array('md5' => md5_file($file_path), 'path' => substr($file_path, $pos + strlen('/html/')), 'category' => $category, 'inserttime' => 'now()'));
     $id = Repository::persist($image);
     return $id;
 }
Пример #7
0
    return;
}
foreach ($tags as $tag) {
    $tag = trim($tag);
    if ($tag == '') {
        continue;
    }
    $tag_id = Repository::findTagIdFromTags(array('eq' => array('tag_name' => $tag)));
    if ($tag_id == false) {
        $tag = new TagsModel(array('tag_name' => $tag, 'inserttime' => 'now()'));
        $tag_id = Repository::persist($tag);
        if ($tag_id == false) {
            LogOpt::set('exception', 'tag 添加失败');
            continue;
        }
    }
    $article_tag_relation = new ArticleTagRelationModel(array('article_id' => $article_id, 'tag_id' => $tag_id, 'inserttime' => 'now()'));
    try {
        $relation_id = Repository::persist($article_tag_relation);
    } catch (PDOException $e) {
        LogOpt::set('exception', 'article_tag_relation 已存在', 'article_id', $article_id, 'tag_id', $tag_id);
        $pdo = Repository::getInstance();
        $pdo->rollback();
        continue;
    }
    if ($relation_id == false) {
        LogOpt::set('exception', 'article_tag_relation 更新失败', 'article_id', $article_id, 'tag_id', $tag_id);
        continue;
    }
    LogOpt::set('info', 'article_tag_relation 更新成功', 'relation_id', $relation_id);
}
Пример #8
0
    return;
}
$bookname = $options['b'];
$image_id = intval(trim($options['i']));
$descs = isset($options['d']) ? $options['d'] : null;
$image = Repository::findOneFromImages(array('eq' => array('image_id' => $image_id)));
if ($image == false) {
    LogOpt::set('exception', 'image not exists', 'image_id', $image_id);
    return false;
}
$article = new ArticleModel(array('title' => $bookname, 'updatetime' => 'now()', 'inserttime' => 'now()', 'category_id' => 2));
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'new_note_insert_into_article_error');
    return false;
}
LogOpt::set('info', 'new_note_insert_into_article_success', 'article_id', $article_id);
$infos = array();
$infos['index_article_id'] = $article_id;
$infos['image_id'] = $image_id;
$infos['updatetime'] = 'now()';
if ($descs != null) {
    $infos['descs'] = $descs;
}
$booknote = new BooknoteModel(array('index_article_id' => $article_id, 'image_id' => $image_id, 'updatetime' => 'now()', 'inserttime' => 'now()'));
$note_id = Repository::persist($booknote);
if ($note_id == false) {
    LogOpt::set('exception', 'new_note_insert_into_booknote_error');
    return false;
}
LogOpt::set('info', 'new_note_insert_into_booknote_success', 'note_id', $note_id);
Пример #9
0
    }
    $mood_id = Repository::persist($mood);
    if ($mood_id === false) {
        LogOpt::set('exception', 'mood add error');
        continue;
    }
    LogOpt::set('info', 'mood add success', 'mood_id', $mood_id);
} else {
    echo 'usage: you can also use by ----' . ' php mood_loader -c contents [-i inserttime] [-d mood_id]' . PHP_EOL;
    while (1) {
        echo '> ';
        $contents = fgets(STDIN);
        $contents = trim($contents);
        if (strtolower($contents) === 'quit') {
            break;
        }
        if ($contents != '' && $contents != null) {
            echo '确认添加至说说吗? Y/N [N]:';
            $sure = fgets(STDIN);
            if (trim($sure[0]) == 'Y' || trim($sure[0]) == 'y') {
                $mood = new MoodModel(array('contents' => $contents));
                $mood_id = Repository::persist($mood);
                if ($mood_id === false) {
                    LogOpt::set('exception', 'mood add error', 'contents', $contents);
                    continue;
                }
                LogOpt::set('info', 'mood add success', 'mood_id', $mood_id);
            }
        }
    }
}
Пример #10
0
    $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
    if ($image_id == false) {
        $full_path = WEB_PATH . '/resource/' . $image_path;
        $image_id = TechlogTools::load_image($full_path, 'article');
        if ($image_id == false) {
            LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
        }
        LogOpt::set('info', '添加图片到数据库成功', 'image_id', $image_id, 'image_path', $image_path);
        $image_ids[] = $image_id;
    }
}
$infos['title'] = date('Y-m-d H:i:s');
if (isset($options['t'])) {
    $infos['title'] = $options['t'] . ' -- ' . date('Y-m-d');
}
$infos['category_id'] = '5';
// 获取 index
$indexs = json_encode(TechlogTools::get_index($contents));
if ($indexs != null) {
    $infos['indexs'] = $indexs;
}
$infos['updatetime'] = 'now()';
$infos['inserttime'] = 'now()';
$article = new ArticleModel($infos);
$article_id = Repository::persist($article);
if ($article_id == false) {
    LogOpt::set('exception', 'article insert error');
    return;
}
LogOpt::set('info', '添加日志成功', 'article_id', $article_id, 'title', $infos['title']);
unlink($draft_file);