Merge remote-tracking branch 'origin/4.6' into 4.6-master-2015-08-03-16-00-35
[civicrm-core.git] / bin / deprecated / EmailProcessor.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
e4f46be0 37 * When running script from cli :
6a488035
TO
38 * 1. By default script is being used for civimail processing.
39 * eg : nice -19 php bin/EmailProcessor.php -u<login> -p<password> -s<sites(or default)>
40 *
41 * 2. Pass "activities" as argument to use script for 'Email To Activity Processing'.
42 * eg : nice -19 php bin/EmailProcessor.php -u<login> -p<password> -s<sites(or default)> activities
43 *
44 */
45
46// bootstrap the environment and run the processor
47// you can run this program either from an apache command, or from the cli
48if (php_sapi_name() == "cli") {
a9e80afc 49 require_once "bin/cli.php";
6a488035
TO
50 $cli = new civicrm_cli();
51 //if it doesn't die, it's authenticated
52 //log the execution of script
53 CRM_Core_Error::debug_log_message('EmailProcessor.php from the cli');
33c5988b 54 $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
6a488035
TO
55
56 if (!$lock->isAcquired()) {
57 throw new Exception('Could not acquire lock, another EmailProcessor process is running');
58 }
59
60 require_once 'CRM/Utils/Mail/EmailProcessor.php';
61
62 // check if the script is being used for civimail processing or email to
63 // activity processing.
64 if (isset($cli->args[0]) && $cli->args[0] == "activities") {
65 CRM_Utils_Mail_EmailProcessor::processActivities();
66 }
67 else {
68 CRM_Utils_Mail_EmailProcessor::processBounces();
69 }
70 $lock->release();
71}
72else {
73 session_start();
74 require_once '../civicrm.config.php';
75 require_once 'CRM/Core/Config.php';
76 $config = CRM_Core_Config::singleton();
77 CRM_Utils_System::authenticateScript(TRUE);
78
79 require_once 'CRM/Utils/System.php';
80 CRM_Utils_System::loadBootStrap();
81
82 //log the execution of script
83 CRM_Core_Error::debug_log_message('EmailProcessor.php');
84
33c5988b 85 $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
6a488035
TO
86
87 if (!$lock->isAcquired()) {
88 throw new Exception('Could not acquire lock, another EmailProcessor process is running');
89 }
90
91 // try to unset any time limits
92 if (!ini_get('safe_mode')) {
93 set_time_limit(0);
94 }
95
96 require_once 'CRM/Utils/Mail/EmailProcessor.php';
97
98 // cleanup directories with old mail files (if they exist): CRM-4452
99 CRM_Utils_Mail_EmailProcessor::cleanupDir($config->customFileUploadDir . DIRECTORY_SEPARATOR . 'CiviMail.ignored');
100 CRM_Utils_Mail_EmailProcessor::cleanupDir($config->customFileUploadDir . DIRECTORY_SEPARATOR . 'CiviMail.processed');
101
102 // check if the script is being used for civimail processing or email to
103 // activity processing.
0d8afee2 104 $isCiviMail = !empty($_REQUEST['emailtoactivity']) ? FALSE : TRUE;
6a488035
TO
105 CRM_Utils_Mail_EmailProcessor::process($isCiviMail);
106
107 $lock->release();
108}