-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.driver.php
159 lines (121 loc) · 4.27 KB
/
extension.driver.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
require_once EXTENSIONS.'/xmlimporter/lib/class.xmlimporter.php';
require_once(TOOLKIT . '/class.administrationpage.php');
require_once(TOOLKIT . '/class.extensionmanager.php');
require_once(TOOLKIT . '/class.gateway.php');
require_once(TOOLKIT . '/class.fieldmanager.php');
require_once(TOOLKIT . '/class.entrymanager.php');
require_once(TOOLKIT . '/class.sectionmanager.php');
require_once(TOOLKIT . '/class.general.php');
require_once(EXTENSIONS . '/xmlimporter/lib/class.xmlimporterhelpers.php');
class extension_xmlimport_notifier extends Extension
{
//public $total = 0;
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/xmlimporter/importers/run/',
'delegate' => 'XMLImporterEntryPostCreate',
'callback' => '__entryCreated'
),
array(
'page' => '/xmlimporter/importers/run/',
'delegate' => 'XMLImporterEntryPostEdit',
'callback' => '__entryEdited'
),
array(
'page' => '/xmlimporter/importers/run/',
'delegate' => 'XMLImporterImportPostRun',
'callback' => 'EmailNotify'
),
array(
'page' => '/xmlimporter/importers/run/',
'delegate' => 'XMLImporterImportPostRunErrors',
'callback' => 'EmailNotifyErrors'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePreferences'
),
);
}
public function __construct()
{
parent::__construct();
//self::EmailNotifier();
//var_dump($this->total);
}
public function __entryCreated($context)
{
$one = count($context['entry']);
//
//self::totalCount($one);
}
public function __entryEdited($context)
{
$one = count($context['entry']);
//
//self::totalCount($one);
}
public function EmailNotify($context)
{
//var_dump($context);
$created = $context[0];
$updated = $context[1];
$skipped = $context[2];
$email = Symphony::Configuration()->get('email','xmlimport_notifier');
if($created >0 || $updated > 0 || $skipped > 0)
//Send email with message of Total count of import entries.
if($email !='')
{
$message = "A total of ".$created." new Entries have been created, ".$updated." entries updated and ".$skipped." entries skipped";
$mail = mail($email, 'XMLimporter Report', $message);
}
//Notify Admin of no Email Address being set.
else{
$message="XMLimport Notifier Email is not set in preferences, no email notification was sent";
Administration::instance()->Page->pageAlert($message, Alert::ERROR);
}
}
public function EmailNotifyErrors($context)
{
var_dump($context);
//$created = $context[0];
//$updated = $context[1];
//$skipped = $context[2];
//var_dump($created,$updated,$skipped);
/*if($created >0 || $updated > 0 || $skipped > 0)
{
$message = "A total of ".$created." new Entries have been created, ".$updated." entries updated and ".$skipped." entries skipped";
$mail = mail('me@localhost', 'My Subject', $message);
}*/
}
// Check for Email entry in config for this extension.. if no email Throw notification to page and email the admin account to notify that Importers don't have a specified email address set..
public function install()
{
Symphony::Configuration()->set('email','','xmlimport_notifier');
Administration::instance()->saveConfig();
}
public function uninstall(){
Symphony::Configuration()->remove('xmlimport_notifier');
Administration::instance()->saveConfig();
}
public function savePreferences($context){
}
public function appendPreferences($context){
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', __('XMLimport Notifier')));
$label = Widget::Label(__('Email Address to notify'));
$label->appendChild(Widget::Input('settings[xmlimport_notifier][email]', General::Sanitize(Symphony::Configuration()->get('email', 'xmlimport_notifier'))));
$fieldset->appendChild($label);
$context['wrapper']->appendChild($fieldset);
}
}