-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch_action.php
67 lines (49 loc) · 1.63 KB
/
match_action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once('twitter_message.php');
require_once('tweet_action.php');
require_once('data_helper.php');
class match_action extends tweet_action
{
var $matches = array();
function process()
{
global $log;
$log->logInfo('');
$log->logInfo('');
$log->logInfo('Starting Match Action!!!!');
$keywords = DataHelper::getKeywords(true);
$keywords = array_keys($keywords);
$this->matches = $this->m_tweet->contains($keywords);
$log->logInfo('Done Match Action!!!!');
$log->logInfo('');
$log->logInfo('');
return $this->get_last_error_code()==0 && !empty($this->matches);
}
function save()
{
if (empty($this->matches))
return false;
global $log;
try
{
//Save tweet
$tweet_id = $this->tweet->save();
//Save the keyword relation
global $DB;
foreach ($this->matches as $matched_keyword)
{
$insert_id = $DB->query("INSERT IGNORE INTO tweet_relations(tweet_id, keyword_id) VALUES (?, SELECT id FROM keywords where keyword = ?)",
$tweet_id, $matched_keyword);
$log->logInfo("Added tweet relation of " . $matched_keyword . " with " . $tweet_id . ". Relation id = " . $$insert_id);
}
return true;
}
catch (Exception $exp)
{
exception_handler($exp);
$log->logCrit("Exception in match_action::save", $exp);
return false;
}
}
}
?>