Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
IdValueTypeSanitizerUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
47  {
53  protected $type;
54 
55  public static function getLinkedMappingRuleType()
56  {
57  return 'IdValueType';
58  }
59 
64  {
65  return true;
66  }
67 
71  public function analyzeByRow(RedBean_OODBBean $rowBean)
72  {
73  if ($rowBean->{$this->columnName} == null)
74  {
75  $found = false;
76  }
77  elseif ($this->mappingRuleData["type"] == IdValueTypeMappingRuleForm::ZURMO_MODEL_ID)
78  {
79  $found = $this->resolveFoundIdByValue($rowBean->{$this->columnName});
80  }
81  else
82  {
83  $found = $this->resolveFoundExternalSystemIdByValue($rowBean->{$this->columnName});
84  }
85  $this->resolveFindingModelDuringAnalysis($found, $rowBean);
86  $this->resolveExternalSystemIdValueIsTooLong($rowBean);
87  }
88 
89  protected function resolveFindingModelDuringAnalysis($found, RedBean_OODBBean $rowBean)
90  {
91  assert('is_bool($found)');
92  if ($found)
93  {
94  $this->resolveForFoundModel();
95  }
96  else
97  {
98  $this->resolveForUnfoundModel($rowBean);
99  }
100  }
101 
102  protected function resolveExternalSystemIdValueIsTooLong(RedBean_OODBBean $rowBean)
103  {
104  if ($this->mappingRuleData["type"] == IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID)
105  {
106  if (strlen($rowBean->{$this->columnName}) > $this->externalSystemIdMaxLength)
107  {
108  $label = Zurmo::t('ImportModule', 'Is too long.');
109  $this->shouldSkipRow = true;
110  $this->analysisMessages[] = $label;
111  }
112  }
113  }
114 
115  protected function resolveForUnfoundModel(RedBean_OODBBean $rowBean)
116  {
117  if ($rowBean->{$this->columnName} != null)
118  {
119  $label = Zurmo::t('ImportModule', 'Was not found and this row will be skipped during import.');
120  $this->shouldSkipRow = true;
121  $this->analysisMessages[] = $label;
122  }
123  }
124 
129  protected function ensureTypeValueIsValid($type)
130  {
131  assert('$type == IdValueTypeMappingRuleForm::ZURMO_MODEL_ID ||
132  $type == IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID');
133  }
134 
135  protected function assertMappingRuleDataIsValid()
136  {
137  assert('$this->mappingRuleData["type"] == IdValueTypeMappingRuleForm::ZURMO_MODEL_ID ||
138  $this->mappingRuleData["type"] == IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID');
139  }
140 
141  protected function resolveMappingRuleDataType()
142  {
143  if (!isset($this->mappingRuleData["type"]) || $this->mappingRuleData["type"] == null)
144  {
145  $this->mappingRuleData["type"] = IdValueTypeMappingRuleForm::ZURMO_MODEL_ID;
146  }
147  }
148 
149  protected function init()
150  {
151  parent::init();
152  $this->resolveMappingRuleDataType();
153  $modelClassName = $this->modelClassName;
154  $model = new $modelClassName(false);
155  $this->attributeModelClassName = $this->resolveAttributeModelClassName($model, $this->attributeName);
156  $this->ensureTypeValueIsValid($this->mappingRuleData["type"]);
157  if ($this->mappingRuleData["type"] == IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID)
158  {
159  $modelClassName = $this->attributeModelClassName;
160  ExternalSystemIdUtil::addExternalIdColumnIfMissing($modelClassName::getTableName(),
161  $this->externalSystemIdMaxLength);
162  }
163  }
164  }
165 ?>
static addExternalIdColumnIfMissing($tableName, $maxLength=255, $columnName=null)
analyzeByRow(RedBean_OODBBean $rowBean)
Generated on Wed Oct 21 2020 07:10:31
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.