|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class CampaignMonitorAddOldCampaigns extends BuildTask |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
protected $title = "Retrieves a list of campaigns from Campaign Monitor."; |
|
8
|
|
|
|
|
9
|
|
|
protected $description = "Retrieves a list of campaigns from Campaign Monitor for future display."; |
|
10
|
|
|
|
|
11
|
|
|
protected $verbose = true; |
|
12
|
|
|
|
|
13
|
|
|
public function setVerbose($b) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->verbose = $b; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param SS_HTTP_Request |
|
20
|
|
|
* standard method |
|
21
|
|
|
*/ |
|
22
|
|
|
public function run($request) |
|
23
|
|
|
{ |
|
24
|
|
|
$faultyOnes = CampaignMonitorCampaign::get()->where("(\"CampaignID\" = '' OR \"CampaignID\" IS NULL) AND (\"WebVersionURL\" IS NOT NULL && \"WebVersionURL\" <> '')"); |
|
25
|
|
|
foreach ($faultyOnes as $faultyOne) { |
|
26
|
|
|
$faultyOne->delete(); |
|
27
|
|
|
} |
|
28
|
|
|
$api = CampaignMonitorAPIConnector::create(); |
|
29
|
|
|
$api->init(); |
|
30
|
|
|
$campaigns = $api->getCampaigns(); |
|
31
|
|
|
if (is_array($campaigns)) { |
|
32
|
|
|
foreach ($campaigns as $campaign) { |
|
33
|
|
|
if ($campaign->SentDate) { |
|
34
|
|
|
$campaignMonitorCampaign = CampaignMonitorCampaign::get()->filter(array("CampaignID" => $campaign->CampaignID))->first(); |
|
35
|
|
|
if (!$campaignMonitorCampaign) { |
|
36
|
|
|
if ($this->verbose) { |
|
37
|
|
|
DB::alteration_message("Adding ".$campaign->Subject." sent ".$campaign->SentDate, "created"); |
|
38
|
|
|
} |
|
39
|
|
|
$campaignMonitorCampaign = CampaignMonitorCampaign::create(); |
|
40
|
|
|
} else { |
|
41
|
|
|
if ($this->verbose) { |
|
42
|
|
|
DB::alteration_message("already added ".$campaign->Subject, "edited"); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
$campaignMonitorCampaign->HasBeenSent = true; |
|
46
|
|
|
$campaignMonitorCampaign->CampaignID = $campaign->CampaignID; |
|
47
|
|
|
$campaignMonitorCampaign->Subject = $campaign->Subject; |
|
48
|
|
|
$campaignMonitorCampaign->Name = $campaign->Name; |
|
49
|
|
|
$campaignMonitorCampaign->SentDate = $campaign->SentDate; |
|
50
|
|
|
$campaignMonitorCampaign->WebVersionURL = $campaign->WebVersionURL; |
|
51
|
|
|
$campaignMonitorCampaign->WebVersionTextURL = $campaign->WebVersionTextURL; |
|
52
|
|
|
//$CampaignMonitorCampaign->ParentID = $this->ID; |
|
|
|
|
|
|
53
|
|
|
$campaignMonitorCampaign->write(); |
|
54
|
|
|
} else { |
|
55
|
|
|
if ($this->verbose) { |
|
56
|
|
|
DB::alteration_message("not adding ".$campaign->Subject." because it has not been sent yet...", "edited"); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} else { |
|
61
|
|
|
if ($this->verbose) { |
|
62
|
|
|
DB::alteration_message("there are no campaigns to be added", "edited"); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
if ($this->verbose) { |
|
66
|
|
|
DB::alteration_message("<hr /><hr /><hr />Completed", "edited"); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|