Skip to content

Commit 70e3289

Browse files
author
Xenomporio
committed
Merge branch 'develop'
2 parents ff7f916 + b27b5d1 commit 70e3289

12 files changed

+7385
-6887
lines changed

conf/main.conf.php.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Config
1313
{
1414
/** @var string */
15-
public $updateHost = 'update.xentral.biz';
15+
public $updateHost = 'removed.upgrade.host';
1616
1717
public function __construct()
1818
{

cronjobs/autoversand_manuell.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/*
3+
include(dirname(__FILE__)."/../conf/main.conf.php");
4+
include(dirname(__FILE__)."/../phpwf/plugins/class.mysql.php");
5+
include(dirname(__FILE__)."/../www/lib/imap.inc.php");
6+
include(dirname(__FILE__)."/../www/lib/class.erpapi.php");
7+
8+
class app_t {
9+
var $DB;
10+
var $user;
11+
}
12+
*/
13+
// ende debug
14+
15+
/*
16+
$debugfile = "/var/www/html/Xenomporio/debug.txt";
17+
18+
function file_append($filename,$text) {
19+
$oldtext = file_get_contents($filename);
20+
file_put_contents($filename,$oldtext.$text);
21+
}
22+
23+
file_put_contents($debugfile,"1");
24+
*/
25+
26+
if(empty($app)){
27+
$app = new app_t();
28+
}
29+
$DEBUG = 0;
30+
31+
if(empty($app->Conf)){
32+
$conf = new Config();
33+
$app->Conf = $conf;
34+
}
35+
if(empty($app->DB) || empty($app->DB->connection)){
36+
$app->DB = new DB($app->Conf->WFdbhost, $app->Conf->WFdbname, $app->Conf->WFdbuser, $app->Conf->WFdbpass, null, $app->Conf->WFdbport);
37+
}
38+
if(empty($app->erp)){
39+
if(class_exists('erpAPICustom')){
40+
$erp = new erpAPICustom($app);
41+
}else{
42+
$erp = new erpAPI($app);
43+
}
44+
$app->erp = $erp;
45+
}
46+
$app->String = new WawiString();
47+
if(class_exists('RemoteCustom'))
48+
{
49+
$app->remote = new RemoteCustom($app);
50+
}else{
51+
$app->remote = new Remote($app);
52+
}
53+
$app->Secure = new Secure($app);
54+
$app->User = new User($app);
55+
if(!defined('FPDF_FONTPATH'))
56+
{
57+
define('FPDF_FONTPATH',dirname(__DIR__) . '/www/lib/pdf/font/');
58+
}
59+
60+
$cronjobname = 'autoversand_manuell';
61+
62+
$mutex = $app->DB->Select(
63+
"SELECT MAX(`mutex`) FROM `prozessstarter` WHERE (`parameter` = '".$cronjobname."')"
64+
);
65+
if($mutex){
66+
$app->DB->Update(
67+
"UPDATE `prozessstarter`
68+
SET `mutexcounter`=`mutexcounter`+1
69+
WHERE `mutex` = 1 AND (`parameter` = '".$cronjobname."')"
70+
);
71+
72+
file_append($debugfile,"MUTEX");
73+
74+
return;
75+
}
76+
$app->DB->Update(
77+
"UPDATE `prozessstarter` SET `mutex`='1', `mutexcounter` = 0 WHERE (`parameter` = '".$cronjobname."')"
78+
);
79+
80+
// START APPLICATION
81+
82+
$objAuftrag = $app->loadModule('auftrag');
83+
if($objAuftrag == null || !method_exists($objAuftrag, 'AuftragVersand')) {
84+
$app->erp->LogFile($cronjobname." failed. Error while loading module 'auftrag'.");
85+
exit;
86+
}
87+
88+
$pendingorders = $app->DB->SelectArr(
89+
"SELECT id
90+
FROM auftrag AS a
91+
WHERE a.id!='' AND (a.belegnr!=0 OR a.belegnr!='')
92+
AND a.status='freigegeben' AND a.cronjobkommissionierung > 0"
93+
);
94+
95+
if (!is_null($pendingorders)) {
96+
97+
$processed_orders_num = 0;
98+
foreach ($pendingorders as $pendingorder) {
99+
/* Process each order */
100+
101+
if($objAuftrag->AuftragVersand($pendingorder['id'],true)) { // Ignore shipdate -> The order has been marked, send it
102+
$processed_orders_num++;
103+
} else {
104+
}
105+
// Limit to 10 per call
106+
if ($processed_orders_num > 10) {
107+
break;
108+
}
109+
}
110+
}
111+
112+
// END APPLICATION
113+
114+
$app->DB->Update("UPDATE prozessstarter SET mutex = 0 , mutexcounter = 0, letzteausfuerhung = now() WHERE (parameter = '".$cronjobname."' ) AND aktiv = 1");

cronjobs/tickets.php

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
<?php
2+
3+
/*
4+
* Fetch all mails for accounts with ticket function
5+
* Create tickets or sort mails to existing tickets
6+
*/
7+
8+
use Xentral\Components\Logger\Logger;
9+
use Xentral\Components\MailClient\MailClientFactory;
10+
use Xentral\Modules\SystemMailClient\MailClientConfigProvider;
11+
use Xentral\Modules\SystemMailer\Service\EmailAccountGateway;
12+
use Xentral\Modules\Ticket\Importer\TicketFormatter;
13+
use Xentral\Modules\Ticket\Task\TicketImportHelperFactory;
14+
15+
$DEBUG = 0;
16+
17+
18+
$debugfile = "/var/www/html/Xenomporio/debug.txt";
19+
20+
function file_append($filename,$text) {
21+
$oldtext = file_get_contents($filename);
22+
file_put_contents($filename,$oldtext.$text);
23+
}
24+
25+
file_put_contents($debugfile,"0");
26+
27+
/** @var ApplicationCore $app */
28+
29+
$erp = $app->erp;
30+
$conf = $app->Conf;
31+
32+
/** @var Logger $logger */
33+
$logger = $app->Container->get('Logger');
34+
35+
$cronjobname = 'tickets';
36+
/*
37+
$mutex = $app->DB->Select(
38+
"SELECT MAX(`mutex`) FROM `prozessstarter` WHERE (`parameter` = '".$cronjobname."')"
39+
);
40+
if($mutex){
41+
$app->DB->Update(
42+
"UPDATE `prozessstarter`
43+
SET `mutexcounter`=`mutexcounter`+1
44+
WHERE `mutex` = 1 AND (`parameter` = '".$cronjobname."')"
45+
);
46+
47+
file_append($debugfile,"MUTEX");
48+
49+
return;
50+
}
51+
$app->DB->Update(
52+
"UPDATE `prozessstarter` SET `mutex`='1', `mutexcounter` = 0 WHERE (`parameter` = '".$cronjobname."')"
53+
);
54+
*/
55+
56+
// get all email Accounts that have the ticket system active
57+
/** @var EmailAccountGateway $accountGateway */
58+
$accountGateway = $app->Container->get('EmailAccountGateway');
59+
$accounts = $accountGateway->getAccountsWithTicketActive();
60+
61+
file_append($debugfile,"Accs:".count($accounts).";");
62+
63+
64+
// only load services if there is at least one account to import (performance)
65+
$ticketModule = null;
66+
$factory = null;
67+
$configProvider = null;
68+
$formatHelper = null;
69+
$importHelperFactory = null;
70+
if(!empty($accounts)){
71+
/** @var Ticket $ticketModule */
72+
$ticketModule = $app->erp->LoadModul('ticket');
73+
/** @var MailClientFactory $factory */
74+
$factory = $app->Container->get('MailClientFactory');
75+
/** @var MailClientConfigProvider $configProvider */
76+
$configProvider = $app->Container->get('MailClientConfigProvider');
77+
/** @var TicketFormatter $formatHelper */
78+
$formatHelper = $app->Container->get('TicketFormatter');
79+
/** @var TicketImportHelperFactory $importHelperFactory */
80+
$importHelperFactory = $app->Container->get('TicketImportHelperFactory');
81+
}
82+
83+
$totalEmailsImportCount = 0;
84+
foreach ($accounts as $account) {
85+
$logger->debug(
86+
'Start imap ticket import for {email}',
87+
['email' => $account->getEmailAddress(), 'account' => $account]
88+
);
89+
90+
file_append($debugfile,"Account ".$account->getemailAddress());
91+
92+
// create mail client
93+
try {
94+
$mailConfig = $configProvider->createImapConfigFromAccount($account);
95+
$mailClient = $factory->createImapClient($mailConfig);
96+
} catch (Exception $e) {
97+
$logger->error('Failed to create email client', ['error' => (string)$e, 'account' => $account]);
98+
99+
file_append($debugfile,"Failed 1");
100+
101+
continue;
102+
}
103+
104+
file_append($debugfile,"Connect to ".."SSL: ".$configProvider->isSslEnabled()." auth ".getAuthType()."\n");
105+
106+
// connect mail client
107+
try {
108+
try {
109+
$mailClient->connect();
110+
111+
file_append($debugfile,"Meh");
112+
113+
} catch (Exception $e) {
114+
$logger->error('Error during imap connection', ['error' => (string)$e, 'account' => $account]);
115+
116+
file_append($debugfile,"Error ".(string)$e);
117+
118+
continue;
119+
}
120+
}
121+
122+
file_append($debugfile,"2");
123+
124+
// connet to INBOX folder
125+
try {
126+
$mailClient->selectFolder('INBOX');
127+
} catch (Exception $e) {
128+
$logger->error('Failed to select INBOX folder', ['error' => (string)$e, 'account' => $account]);
129+
130+
131+
file_append($debugfile,"Failed 2");
132+
133+
134+
continue;
135+
}
136+
137+
$projectId = $account->getProjectId() > 0 ? $account->getProjectId() : 1;
138+
$delete_msg = 0;
139+
$daysold = $account->getBackupDeleteAfterDays();
140+
141+
// determine search criteria for new messages
142+
$datet = '2012-12-24';
143+
if ($account->getImportStartDateAsString() !== '0000-00-00') {
144+
$datesince = date('d-M-Y', strtotime($account->getImportStartDateAsString()));
145+
$criteria = 'UNSEEN SINCE ' . $datesince;
146+
} else {
147+
$criteria = 'UNSEEN';
148+
}
149+
150+
file_append($debugfile,"3");
151+
152+
// search new messages
153+
try {
154+
$searchResult = $mailClient->searchMessages($criteria);
155+
} catch (Exception $e) {
156+
$logger->error('Error during imap search', ['exception' => $e]);
157+
158+
file_append($debugfile,"Failed 3");
159+
160+
161+
continue;
162+
}
163+
$logger->debug('unread emails to import: {message_count}', ['message_count' => count($searchResult)]);
164+
165+
// set mutex if there is more than 5 emails to import
166+
if (count($searchResult) > 5) {
167+
$app->DB->Update(
168+
"UPDATE `prozessstarter`
169+
SET `mutex`=1, `mutexcounter` = 0, `letzteausfuerhung` = NOW()
170+
WHERE (`parameter` = '".$cronjobname."')"
171+
);
172+
}
173+
$importer = $importHelperFactory->create($mailClient, $account, $projectId);
174+
$insertedMailsCount = $importer->importMessages($searchResult);
175+
$totalEmailsImportCount += $insertedMailsCount;
176+
177+
// set mutex if the total amount of imported emails is more than 10
178+
if ($totalEmailsImportCount > 10) {
179+
$app->DB->Update(
180+
"UPDATE `prozessstarter`
181+
SET `mutex`=1, `mutexcounter` = 0, `letzteausfuerhung` = NOW()
182+
WHERE (`parameter` = '".$cronjobname."')"
183+
);
184+
}
185+
186+
$mailClient->expunge();
187+
$mailClient->disconnect();
188+
189+
if (
190+
method_exists($app->erp, 'canRunCronjob')
191+
&& !$app->erp->canRunCronjob(['supportmails', 'tickets'])
192+
) {
193+
194+
$logger->error('Tickets error');
195+
196+
file_append($debugfile,"Failed 5");
197+
198+
199+
return;
200+
}
201+
$app->DB->Update(
202+
"UPDATE `prozessstarter`
203+
SET `mutex`=1, `mutexcounter` = 0, `letzteausfuerhung` = NOW()
204+
WHERE (`parameter` = '".$cronjobname."')"
205+
);
206+
}
207+
208+
$app->DB->Update(
209+
"UPDATE `prozessstarter` SET `mutex`=0,`mutexcounter`=0 WHERE (`parameter` = '".$cronjobname."')"
210+
);
211+
212+
file_append($debugfile,"END");

database/struktur.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10365,7 +10365,7 @@ CREATE TABLE IF NOT EXISTS `proformarechnung_protokoll` (
1036510365
CREATE TABLE IF NOT EXISTS `projekt` (
1036610366
`id` int(10) NOT NULL AUTO_INCREMENT,
1036710367
`name` text NOT NULL,
10368-
`abkuerzung` text NOT NULL,
10368+
`abkuerzung` varchar(128) NOT NULL,
1036910369
`verantwortlicher` text NOT NULL,
1037010370
`beschreibung` text NOT NULL,
1037110371
`sonstiges` text NOT NULL,

0 commit comments

Comments
 (0)