forked from delahaye/convertx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Job.php
144 lines (117 loc) · 3.65 KB
/
Job.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
<?php
/**
* ConvertX
* Extension for Contao Open Source CMS (contao.org)
*
* Copyright (c) 2015 de la Haye
*
* @author Christian de la Haye
* @link http://delahaye.de
* @license Commercial - all rights reserved
*/
namespace Delahaye\ConvertX;
use Delahaye\ConvertX\Helper;
use Delahaye\ConvertX\Model\Converter as ConverterModel;
use Delahaye\ConvertX\Model\Job as JobModel;
use Delahaye\ConvertX\Model\Step as StepModel;
/**
* Class Job
*
* Import job
*
* @package Delahaye\ConvertX
*/
class Job
{
/**
* Find a job
*
* @param $intJob
* @return \Model|null|object
*/
public static function findJob($intJob)
{
// get job data
$objJob = JobModel::findByPk($intJob);
if ($objJob) {
return $objJob;
}
// abort if no job data
$objJob = (object)null;
$objJob->title = sprintf($GLOBALS['TL_LANG']['tl_convertx_job']['jobId'], $intJob);
$objJob->error = $GLOBALS['TL_LANG']['tl_convertx_job']['noJob'];
return $objJob;
}
/**
* Get the steps of a job
*
* @param $intPid
* @return array
*/
public static function findSteps($intPid)
{
$objSteps = StepModel::findBy(array('tl_convertx_step.pid=?', 'tl_convertx_step.published=?'), array($intPid, 1), array('order' => 'sorting'));
if (!$objSteps) {
return array();
}
while ($objSteps->next()) {
$arrSteps[] = $objSteps->id;
}
return $arrSteps;
}
/**
* Find the internal and external target tables (tmp versions)
*
* @param $intPid
* @return array
*/
public static function findTargetTables($intPid)
{
$objJob = JobModel::findByPk($intPid);
$arrTargets = Helper::arrayOnly($objJob->targetTables);
$objSteps = StepModel::findBy(array('tl_convertx_step.pid=?', 'tl_convertx_step.published=?', 'tl_convertx_step.action=?'), array($intPid, 1, 'converter'));
if (!$objSteps) {
return $arrTargets;
}
while ($objSteps->next()) {
$objConverter = ConverterModel::findByPk($objSteps->converter);
switch ($objConverter->targetType) {
case 'InternalTable':
// table names for internal data
$arrTargets[] = 'cvx_' . $objConverter->targetTable;
break;
default:
// tmp tables for external data get a name based on the converter id
$arrTargets[] = 'cvx_' . $objConverter->id;
break;
}
}
return array_unique($arrTargets);
}
/**
* Find the internal and external source tables (tmp versions)
*
* @param $intPid
* @return array
*/
public static function findTmpSourceTables($intPid)
{
$objSteps = StepModel::findBy(array('tl_convertx_step.pid=?', 'tl_convertx_step.published=?', 'tl_convertx_step.action=?'), array($intPid, 1, 'converter'));
if (!$objSteps) {
return array();
}
while ($objSteps->next()) {
$objConverter = ConverterModel::findByPk($objSteps->converter);
switch ($objConverter->sourceType) {
case 'InternalTable':
// for internal sources we don't need tmp tables
break;
default:
// tmp tables for external data get a name based on the converter id
$arrSources[] = 'cvx_' . $objConverter->id . '_source';
break;
}
}
return (array) $arrSources;
}
}