All Data Structures Functions Variables Pages
ModelIntegrationIntegrityCheckJob.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 
41  {
42  protected $modelsToCheck = array();
43 
44  abstract public function getNotificationType();
45 
46  abstract public function getNotificationRulesClassName();
47 
48  abstract public function getNotificationMessage();
49 
50  public static function getRecommendedRunFrequencyContent()
51  {
52  return Zurmo::t('Core', 'Once per day.');
53  }
54 
61  {
62  $addedRequiredAttributesViaDesigner = array();
63  foreach ($models as $modelClassName)
64  {
65  $requiredAttributes = $this->resolveRequiredAttributesFromMetadata($modelClassName::getMetadata(), true);
66  $defaultRequiredAttributes = $this->resolveRequiredAttributesFromMetadata($modelClassName::getDefaultMetadata());
67  $addedRequiredAttributesViaDesignerForModel = $this->resolveAddedRequiredAttributesViaDesigner(
68  $defaultRequiredAttributes, $requiredAttributes);
69 
70  if (!empty($addedRequiredAttributesViaDesignerForModel))
71  {
72  $addedRequiredAttributesViaDesigner[$modelClassName] = $addedRequiredAttributesViaDesignerForModel;
73  }
74  }
75  return $addedRequiredAttributesViaDesigner;
76  }
77 
82  protected function sendNotificationMessages($addedRequiredAttributesViaDesigner)
83  {
84  $message = '';
85  foreach ($addedRequiredAttributesViaDesigner as $modelClassName => $attributes)
86  {
87  foreach ($attributes as $attributeName)
88  {
89  $message .= $modelClassName::getModelLabelByTypeAndLanguage('Singular', Yii::app()->language) .
90  ':' . $modelClassName::getAnAttributeLabel($attributeName) . '<br />';
91  }
92  }
93 
94  $notificationMessage = new NotificationMessage();
95  $notificationMessage->htmlContent = static::getNotificationMessage() . '<br />' . $message;
96  $notificationRulesClassName = static::getNotificationRulesClassName();
97  $rules = new $notificationRulesClassName();
98  $superAdminGroup = Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME);
99  foreach ($superAdminGroup->users as $user)
100  {
101  Notification::deleteByTypeAndUser(static::getNotificationType(), $user);
102  $rules->addUser($user);
103  NotificationsUtil::submit($notificationMessage, $rules);
104  }
105  }
106 
113  protected function resolveAddedRequiredAttributesViaDesigner($defaultRequiredAttributes, $requiredAttributes)
114  {
115  $addedRequiredAttributesViaDesigner = array();
116  if (is_array($requiredAttributes) && !empty($requiredAttributes))
117  {
118  foreach ($requiredAttributes as $modelClassName => $rules)
119  {
120  if (is_array($rules) && !empty($rules))
121  {
122  foreach ($rules as $attributeName => $value)
123  {
124  if (!isset($defaultRequiredAttributes[$modelClassName][$attributeName]) ||
125  $defaultRequiredAttributes[$modelClassName][$attributeName] != $value)
126  {
127  $addedRequiredAttributesViaDesigner[] = $attributeName;
128  }
129  }
130  }
131  }
132  }
133  return $addedRequiredAttributesViaDesigner;
134  }
135 
142  protected function resolveRequiredAttributesFromMetadata($metadata, $onlyWithoutSetDefaultValue = false)
143  {
144  $requiredAttributes = array();
145  foreach ($metadata as $modelClassName => $modelClassMetadata)
146  {
147  if (isset($modelClassMetadata['rules']) &&
148  is_array($modelClassMetadata['rules']) &&
149  !empty($modelClassMetadata['rules']))
150  {
151  foreach ($modelClassMetadata['rules'] as $rule)
152  {
153  if ($rule[1] == 'required')
154  {
155  if ($onlyWithoutSetDefaultValue)
156  {
157  $haveDefaultValue = false;
158  foreach ($modelClassMetadata['rules'] as $innerRule)
159  {
160  // Check if there is default value for same attribute
161  if ($innerRule[1] == 'default' && $innerRule[0] == $rule[0])
162  {
163  $haveDefaultValue = true;
164  }
165  }
166  if (!$haveDefaultValue)
167  {
168  $requiredAttributes[$modelClassName][$rule[0]] = $rule[1];
169  }
170  }
171  else
172  {
173  $requiredAttributes[$modelClassName][$rule[0]] = $rule[1];
174  }
175  }
176  }
177  }
178  }
179  return $requiredAttributes;
180  }
181  }
182 ?>
resolveAddedRequiredAttributesViaDesigner($defaultRequiredAttributes, $requiredAttributes)
static getByName($name)
Definition: Group.php:57
resolveRequiredAttributesFromMetadata($metadata, $onlyWithoutSetDefaultValue=false)
static deleteByTypeAndUser($type, User $user)
sendNotificationMessages($addedRequiredAttributesViaDesigner)
static submit(NotificationMessage $message, NotificationRules $rules)
Generated on Fri Feb 21 2020 07:10:37