Settings.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace ModulesGarden\Servers\KerioEmail\App\Libs\Migrations\Drivers\Version1To2;
  3. use ModulesGarden\Servers\KerioEmail\App\Helpers\KerioManager;
  4. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
  5. /**
  6. * Class Settings
  7. * User: Nessandro
  8. * Date: 2019-11-12
  9. * Time: 19:47
  10. */
  11. class Settings
  12. {
  13. /**
  14. * @var string
  15. */
  16. protected $fromTable = 'mg_prodConfig';
  17. /**
  18. * @var string
  19. */
  20. protected $toTable = '';
  21. /**
  22. * @return string
  23. */
  24. public function getFromTable()
  25. {
  26. return $this->fromTable;
  27. }
  28. /**
  29. * @param $key
  30. * @param $value
  31. * @return array
  32. */
  33. public function unsupported($key, $value)
  34. {
  35. if(strpos($key, 'cos_') === 0)
  36. {
  37. $name = str_replace('cos_', 'cosQuota_', $key);
  38. return [$name, $value];
  39. }
  40. }
  41. /**
  42. * @return array
  43. */
  44. public function getMapped()
  45. {
  46. return [
  47. 'acc_limit' => 'acc_limit',
  48. 'acc_size' => 'acc_size',
  49. 'alias_limit' => 'alias_limit',
  50. 'cos_name' => 'cos_name',
  51. 'dist_list_limit' => 'dist_list_limit',
  52. 'domainMaxSize' => 'domainMaxSize',
  53. 'domain_alias_limit' => 'domain_alias_limit',
  54. 'filterAccountsByCOS' => 'filterAccountsByCOS',
  55. 'login_link' => 'login_link',
  56. 'useCos', //todo ?
  57. 'kerioDumpsterEnabled' => 'kerioDumpsterEnabled',
  58. 'kerioDumpsterPurgeEnabled' => 'kerioDumpsterPurgeEnabled',
  59. 'kerioFeatureAdvancedSearchEnabled' => 'kerioFeatureAdvancedSearchEnabled',
  60. 'kerioFeatureBriefcasesEnabled' => 'kerioFeatureBriefcasesEnabled',
  61. 'kerioFeatureCalendarEnabled' => 'kerioFeatureCalendarEnabled',
  62. 'kerioFeatureCalendarReminderDeviceEmailEnabled' => 'kerioFeatureCalendarReminderDeviceEmailEnabled',
  63. 'kerioFeatureChangePasswordEnabled',
  64. 'kerioFeatureContactsEnabled',
  65. 'kerioFeatureConversationsEnabled',
  66. 'kerioFeatureDistributionListFolderEnabled',
  67. 'kerioFeatureEwsEnabled',
  68. 'kerioFeatureExportFolderEnabled',
  69. 'kerioFeatureFiltersEnabled',
  70. 'kerioFeatureFlaggingEnabled',
  71. 'kerioFeatureGalAutoCompleteEnabled',
  72. 'kerioFeatureGalEnabled',
  73. 'kerioFeatureGroupCalendarEnabled',
  74. 'kerioFeatureHtmlComposeEnabled',
  75. 'kerioFeatureIdentitiesEnabled',
  76. 'kerioFeatureImapDataSourceEnabled',
  77. 'kerioFeatureImportFolderEnabled',
  78. 'kerioFeatureInitialSearchPreferenceEnabled',
  79. 'kerioFeatureMailEnabled',
  80. 'kerioFeatureMailPriorityEnabled',
  81. 'kerioFeatureMailSendLaterEnabled',
  82. 'kerioFeatureManageZimlets',
  83. 'kerioFeatureMAPIConnectorEnabled',
  84. 'kerioFeatureNewMailNotificationEnabled',
  85. 'kerioFeatureOptionsEnabled',
  86. 'kerioFeatureOutOfOfficeReplyEnabled',
  87. 'kerioFeaturePeopleSearchEnabled',
  88. 'kerioFeaturePop3DataSourceEnabled',
  89. 'kerioFeatureReadReceiptsEnabled',
  90. 'kerioFeatureSavedSearchesEnabled',
  91. 'kerioFeatureSharingEnabled',
  92. 'kerioFeatureSkinChangeEnabled',
  93. 'kerioFeatureSMIMEEnabled',
  94. 'kerioFeatureTaggingEnabled',
  95. 'kerioFeatureTasksEnabled',
  96. 'kerioFeatureTouchClientEnabled',
  97. 'kerioFeatureWebClientOfflineAccessEnabled',
  98. 'kerioImapEnabled',
  99. 'kerioPop3Enabled',
  100. ];
  101. }
  102. /**
  103. * @param $params
  104. * @return mixed
  105. */
  106. public function updateValues($params, $prodId)
  107. {
  108. foreach($params as $key => $value)
  109. {
  110. if(strpos($key, 'cos_') === 0 && $key !== 'cos_name')
  111. {
  112. $name = str_replace('cos_', '', $key);
  113. $cos[$name] = $value;
  114. unset($params[$key]);
  115. }
  116. }
  117. if($cos)
  118. {
  119. $params['cos'] = json_encode($cos);
  120. }
  121. /**
  122. * update cosName
  123. *
  124. */
  125. $defaultTypes = [
  126. ClassOfServices::CUSTOM_ZIMBRA,
  127. ClassOfServices::ZIMBRA_CONFIG_OPTIONS,
  128. ClassOfServices::CLASS_OF_SERVICE_QUOTA,
  129. ];
  130. /**
  131. *
  132. *
  133. */
  134. if(!in_array($params['cos_name'], $defaultTypes))
  135. {
  136. $manager = new KerioManager();
  137. $repository = $manager->getApiByProduct($prodId)->soap->repository();
  138. $cosList = $repository->cos->all();
  139. /**
  140. * class of services from API
  141. */
  142. foreach ($cosList as $cos)
  143. {
  144. /**
  145. * @var $cos \ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService
  146. */
  147. $cosList[$cos->getName()] = $cos->getId();
  148. }
  149. $params['cos_name'] = $cosList[$params['cos_name']];
  150. }
  151. return $params;
  152. }
  153. /**
  154. *
  155. * return new fields as name => default value
  156. *
  157. * @return array
  158. */
  159. public function getNewFields()
  160. {
  161. return [
  162. 'clientAreaFeaturesLeft' => 'on',
  163. 'ca_emailAccountPage' => 'on',
  164. 'ca_ressourcePage' => 'on',
  165. 'ca_distributionListPage' => 'on',
  166. 'ca_goToWebmailPage' => 'on',
  167. 'clientAreaFeaturesRight' => 'on',
  168. 'ca_emailAliasesPage' => 'on',
  169. 'ca_domainAliasesPage' => 'on',
  170. ];
  171. }
  172. }