Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

初始化設定問題 #18

Open
kenyiu opened this issue Oct 17, 2014 · 10 comments
Open

初始化設定問題 #18

kenyiu opened this issue Oct 17, 2014 · 10 comments

Comments

@kenyiu
Copy link

kenyiu commented Oct 17, 2014

設定好db後,運行了一次crawler-new.php,但在檢視index.php時出現了404字樣,於是在ErrorController.php加入

echo "<pre>";
echo $this->view->exception;
echo "</pre>";

得出以下訊息。

exception 'Pix_Controller_Dispatcher_Exception' with message '404 Controller file not found: /var/www/newsdiff/webdata/controllers/NewsdiffController.php' in /var/www/newsdiff/webdata/stdlibs/pixframework/Pix/Controller.php:243
Stack trace:
#0 /var/www/newsdiff/index.php(6): Pix_Controller::dispatch('/var/www/newsdi...')
#1 {main}

請問應如何設定?

@ronnywang
Copy link
Owner

你是放在 http://yourdomain.com/newsdiff/ 下面看的嗎?
如果是的話,要改 .htaccess 把 RewriteBase / 改成 RewriteBase /newsdiff

@kenyiu
Copy link
Author

kenyiu commented Oct 17, 2014

改了,仍然有問題 :(
而且,訊息中的NewsdiffController.php,我在整個folder中都找不到。

@ronnywang
Copy link
Owner

試試看在 index.php 的 Pix_Controller::dispatch(DIR . '/webdata/'); 前面加上

$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], strlen('/newsdiff'));

不過不確定會不會出問題
比較好是看看能不能獨立給他個 domain

因為 PixFramework 的使用大部份都是獨立 domain ,因此他看到 /newsdiff 這個網址就跑去找 NewsdiffController 了
但其實應該要找 IndexController 才對

@kenyiu
Copy link
Author

kenyiu commented Oct 17, 2014

謝謝!終於看到畫面了,但似乎連結都壞掉,我還是放在獨立domain好了。

另外,請問應在那裡create table? 因為我本來是靠models下的php, 相應create出table key_value, news, news_info, news_raw

但運行php webdata/scripts/crawler-new.php總是彈出warning, 似乎需要default value。

PHP Warning:  Pix_Table SQL Warning: (1364)Field 'error_count' doesn't have a default value INSERT INTO `news`(`url`, `normalized_id`, `normalized_crc32`, `source`, `created_at`, `last_fetch_at`) VALUES ('http://www.appl in /var/www/newsdiff/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlConf.php on line 187

最後,可以請教一下初始設定步驟為:

  1. Create Tables
  2. Set DATABASE_URL
  3. php webdata/scripts/crawler-new.php
    嗎?

@ronnywang
Copy link
Owner

可以用 php webdata/prompt.php 進入提示字元模式
並且輸入

KeyValue::createTable();
NewsInfo::createTable();
News::createTable();
NewsRaw::createTable();

另外 NewsRaw 那邊之前為了方便砍掉舊資料,會以月份來分 table
如果要開一個月份的 table 可以用

NewsRaw::getDb()->query("CREATE TABLE news_raw_201410 LIKE news_raw")

@ronnywang
Copy link
Owner

我自己現在在跑是每十分鐘會跑一次 crawler-new.php 去抓清單
以及每一分鐘跑三隻 crawler-part.php

分別是
crawler-part.php 0 3
crawler-part.php 1 3
crawler-part.php 2 3

每隻 crawler-part.php 負責 1/3 的新聞來源

@kenyiu
Copy link
Author

kenyiu commented Oct 17, 2014

依據上述方法,在運行crawler-new.php 時仍會有warning

PHP Warning:  Pix_Table SQL Warning: (1364)Field 'error_count' doesn't have a default value INSERT INTO `news`(`url`, `normalized_id`, `normalized_crc32`, `source`, `created_at`, `last_fetch_at`) VALUES ('http://www.appl in /var/www/newsdiff/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlConf.php on line 187

另外,沒有標題,是否正常?(table news_info, news_raw, news_raw_201410 仍然沒有資料寫入)
screenshot from 2014-10-17 16 58 28

最後,所有分頁的連結仍然壞掉,但我已經改回原來版本。

The requested URL /index/source/1 was not found on this server.

@ronnywang
Copy link
Owner

還要跑 crawler-part.php 才會抓內容
可以用 php webdata/scripts/crawler-part.php 0 1 來抓
至於 warning 的部份,可以在 mysql 裡面幫 error_count 加上 default = 0 解決

@kenyiu
Copy link
Author

kenyiu commented Oct 17, 2014

有關warning部分,我還修改了last_changed_at deafult=0, 但仍有訊息如下:

PHP Warning:  Pix_Table SQL Warning: (1265)Data truncated for column 'url' at row 1 INSERT INTO `news`(`url`, `normalized_id`, `normalized_crc32`, `source`, `created_at`, `last_fetch_at`) VALUES ('http://www.appl in /var/www/newsdiff/webdata/stdlibs/pixframework/Pix/Table/Db/Adapter/MysqlConf.php on line 187

所以,我更改了欄位url的類別為text

另外,似乎table news_rawraw亦不夠大,會有data truncated的情況出現,所以更改了欄位raw的類別為mediumtext

謝謝!

@yookoala
Copy link

Pull request #12 修改了預設值,應該可以解決新安裝狀況下發生的預設值 warning 問題。該 pull request 另外亦有資料庫初始化的 script,應該可以簡化初始化設定問題。

yookoala referenced this issue in yookoala/newsdiffHK Jan 7, 2015
原有方法直接用 SQL 語句產生表格,表格的結構不能隨 Pix_Table 實現而改變,比較不靈活。

改用 Ronny 在[這裏](https://github.com/ronnywang/newsdiff/issues/18#issuecomment-59484616)提及的方法產生 news_raw 表格。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants