Permalink
Browse files

save posts to database

  • Loading branch information...
chemix committed Jun 13, 2014
1 parent e471528 commit 2550d2d70c36720526f88bea448864cffda592df
Showing with 53 additions and 1 deletion.
  1. +53 −1 app/presenters/ImportPresenter.php
@@ -25,6 +25,11 @@ class ImportPresenter extends BasePresenter
*/
public $cacheStorage;
/**
* @var \Nette\Database\Context @inject
*/
public $database;
public function renderDefault()
{
FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
@@ -51,7 +56,54 @@ public function renderDefault()
}
}
Dumper::dump($data);
// save data to database
if (is_array($data) && !empty($data)) {
foreach ($data as $rowPost) {
$post = array(
'id' => $rowPost->id,
'type' => $rowPost->type,
'created_time' => $rowPost->created_time,
'updated_time' => $rowPost->updated_time,
);
if (isset($rowPost->name)) {
$post['name'] = $rowPost->name;
}
if (isset($rowPost->link)) {
$post['link'] = $rowPost->link;
}
if (isset($rowPost->status_type)) {
$post['status_type'] = $rowPost->status_type;
}
if (isset($rowPost->message)) {
$post['message'] = $rowPost->message;
}
if (isset($rowPost->caption)) {
$post['caption'] = $rowPost->caption;
}
if (isset($rowPost->picture)) {
$post['picture'] = $rowPost->picture;
}
// post 'status' use story, we need message
if ($rowPost->type == 'status') {
if (isset($rowPost->story)) {
$post['message'] = $rowPost->story;
}
}
try {
$this->database->table('facebook_wallposts')->insert($post);
} catch (\PDOException $e) {
if ($e->getCode() == '23000') {
$this->database->table('facebook_wallposts')->where('id', $rowPost->id)->update($post);
} else {
throw $e;
}
}
}
}
}
}

0 comments on commit 2550d2d

Please sign in to comment.