27141d4a1cdbca857366bf35e8c8f03c1bf7cc5d
[Pman.Core] / Import / Core_email.php
1 <?php
2
3
4
5 require_once 'Pman/Roo.php';
6
7 class Pman_Hydra_Import_Core_email extends Pman_Roo
8 {
9        static $cli_desc = "Import an email into core_email template"; 
10     
11     static $cli_opts = array(
12         'file' => array(
13             'desc' => 'Turn on debugging (see DataObjects debugLevel )',
14             'default' => 0,
15             'short' => 'v',
16             'min' => 1,
17             'max' => 1,
18             
19         ),
20         'list' => array(
21             'desc' => 'List message to send, do not send them..',
22             'default' => 0,
23             'short' => 'l',
24             'min' => 0,
25             'max' => 0,
26             
27         ),
28         'old' => array(
29             'desc' => 'Show old messages.. (and new messages...)',
30             'default' => 0,
31             'short' => 'o',
32             'min' => 0,
33             'max' => 0,
34             
35         ),
36         'force' => array(
37             'desc' => 'Force redelivery, even if it has been sent before or not queued...',
38             'default' => 0,
39             'short' => 'f',
40             'min' => 0,
41             'max' => 0,
42         ),
43         'generate' => array(
44             'desc' => 'Generate notifications for a table, eg. cash_invoice',
45             'default' => '',
46             'short' => 'g',
47             'min' => 0,
48             'max' => 1,
49         ),
50          'limit' => array(
51             'desc' => 'Limit search for no. to send to ',
52             'default' => 1000,
53             'short' => 'L',
54             'min' => 0,
55             'max' => 999,
56         ),
57         'dryrun' => array(
58             'desc' => 'Dry run - do not send.',
59             'default' => 0,
60             'short' => 'D',
61             'min' => 0,
62             'max' => 0,
63         ),
64         'poolsize' => array(
65             'desc' => 'Pool size',
66             'default' => 10,
67             'short' => 'P',
68             'min' => 0,
69             'max' => 100,
70         ),
71     );
72     
73     function getAuth()
74     {
75         $ff = HTML_FlexyFramework::get();
76         
77         if (!$ff->cli) {
78             die("cli only");
79         }
80         
81     }
82
83     function get(){
84         
85         $template_name = 'CORE_PERSON_SIGNUP_CONFIRM';
86         $c = DB_dataObject::factory('core_email');
87         $ret = $c->get('name',$template_name);
88         if($ret == 0){
89             $mailtext = file_get_contents('Pman.Core/templates/mail/'.$template_name.'.txt');
90     
91             require_once 'Mail/mimeDecode.php';  
92             $decoder = new Mail_mimeDecode($mailtext);
93             $parts = $decoder->getSendArray();
94             $from_name = explode(" ", $parts[0])[0];
95             $from_email = explode(" ", $parts[0])[1];
96             $c->setFrom(array(
97                 'from_name'=>$from_name,
98                 'from_email'=>$from_email,
99                 'subject'=>$parts[1]['Subject'],
100                 'name'=>$template_name,
101                 'bodytext'=>$parts[2]
102                 ));
103             $c->insert();
104         }else{
105             print_r("template exists.");
106         }
107
108         die("done\n");
109     }
110 }