Webylon 3.2 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • AdditionalMenuWidget_Item
  • AdvancedSliderHomepageWidget_Item
  • AssetManagerFolder
  • BannerWidget_Item
  • BaseObjectDecorator
  • BookingOrder
  • BookingPaymentMethod
  • BookingService
  • Boolean
  • ButtonsBlockHomepageWidget_Item
  • CarouselHomepageWidget_Item
  • CatalogFilter
  • CatalogRubricsHomepageWidget_CatalogDecorator
  • ClientEmailOrderNotification
  • ClientVKOrderNotification
  • ComponentSet
  • Currency
  • DatabaseAdmin
  • DataObject
  • DataObjectDecorator
  • DataObjectLog
  • DataObjectSet
  • DataObjectSet_Iterator
  • Date
  • DB
  • DBField
  • Decimal
  • DocumentItem
  • DocumentPage_File
  • Double
  • Enum
  • ErrorPageSubsite
  • FileDataObjectTrackingDecorator
  • FileImportDecorator
  • Float
  • FlowerGarden_Size
  • ForeignKey
  • Hierarchy
  • HouseCatalogProductDecorator
  • HTMLText
  • HTMLVarchar
  • Import1CLog
  • Import1CLog_File
  • Import1CLog_Item
  • Import1CLog_Task
  • ImportCatalog1C_PriceType
  • ImportCatalog1C_ProductProp
  • Int
  • ManagerEmailOrderNotification
  • Material3D_File
  • MediawebPage_File
  • MediawebPage_Photo
  • MobileContentDecorator
  • Money
  • MonumentGalleryItem
  • MonumentPhotoGallery
  • MultiEnum
  • MySQLDatabase
  • MySQLQuery
  • Notification
  • OrderDataObject
  • OrderDecorator
  • OrderHandlersDecorator
  • OrderItemDecorator
  • OrderItemVariationDecorator
  • Orders1CExchange_OrdersDecorator
  • OrderService
  • OrderServiceOrder
  • PageIcon
  • PageWidgets
  • Payment
  • PaymentMethodShippingDecorator
  • PaymentOrderExtension
  • Percentage
  • Person
  • PhotoAlbumItem
  • PhotoAlbumProductLinkDecorator
  • PhotoAlbumWidgetLinkDecorator
  • PhotoGalleryHomepageWidget_Item
  • PortraitType
  • PrimaryKey
  • Product3DDecorator
  • ProductCatalogCatalogLinkedDecorator
  • ProductImportLog
  • ProductImportLog_Item
  • ProductParam
  • ProductParamValue
  • ProductVariation
  • RatePeriod
  • RealtyImportLog
  • RealtyImportLog_Item
  • RedirectEntry
  • RoomOrder
  • RoomOrderPerson
  • RoomRate
  • RoomService
  • RoomServiceOrder
  • SberbankPaymentDecorator
  • SeoOpenGraphPageDecorator
  • ServiceOrder
  • ShippingMethodPaymentDecorator
  • ShopCountry
  • SimpleOrderCatalogDecorator
  • SimpleOrderProductDecorator
  • SiteConfigWidgets
  • SiteTreeDecorator
  • SiteTreeImportDecorator
  • SliderHomepageWidget_Item
  • SMSCOrderNotification
  • SMSOrderNotification
  • SortableDataObject
  • SQLMap
  • SQLMap_Iterator
  • SQLQuery
  • SS_Database
  • SS_Datetime
  • SS_Query
  • StringField
  • SubsiteDomain
  • Text
  • TextAnonsWidget_Item
  • Texture3D_File
  • Time
  • Varchar
  • Versioned
  • Versioned_Version
  • VideoCategory
  • VideoEntry
  • VKNotificationQueue
  • WebylonWidget_Item
  • YaMoneyPaymentDecorator
  • Year

Interfaces

  • CompositeDBField
  • CurrentPageIdentifier
  • DataObjectInterface
  1 <?php
  2 
  3 class ProductImportLog extends DataObject {
  4     
  5     static $db = array(
  6         'StartTime' => 'SS_Datetime',
  7         'EndTime' => 'SS_Datetime',
  8         'ProductCatalogDate' => 'SS_Datetime',      
  9         'Status' => "Enum('process,ok,error')",
 10         'StatusMessage' => 'Text',
 11         'Log' => 'Text',
 12         //'TestLog' => 'Text',
 13     );
 14     
 15     static $has_many = array(
 16         'LogItems' => 'ProductImportLog_Item'
 17     );
 18     
 19     
 20     static $searchable_fields = array(
 21 //      'StartTime', //!!! TODO добавить в форму - форму надо делать вручную
 22         'Status',
 23     );
 24    
 25     static $summary_fields = array(
 26         'StartTime',
 27         'EndTime',
 28         'Duration',
 29         'TextStatus',
 30         'StatusMessage',     
 31         'ProductCatalogDate',                   
 32     );
 33     
 34     static $default_sort = 'ID DESC';
 35     
 36     static function get_last_log($successOnly = false) {
 37         $where = ($successOnly) ? '`Status` = "ok"' : '';
 38         return DataObject::get_one('ProductImportLog', $where, true, 'ID DESC');
 39     }
 40     
 41     static function optimize_log_tables($max_log_count) {
 42         $max_log_count -= 1;
 43         $oldImportLogs = DataObject::get('ProductImportLog', '', 'ID DESC', '', "$max_log_count,100");
 44         if ($oldImportLogs) {
 45             foreach($oldImportLogs as $oldImportLog) {
 46                 $oldImportLog->delete();
 47             }
 48         }
 49         DB::Query("OPTIMIZE TABLE `ProductImportLog_Item`");
 50         DB::Query("OPTIMIZE TABLE `ProductImportLog`");
 51     }
 52 
 53     function fieldLabels($includerelations = true) {
 54         $labels = parent::fieldLabels($includerelations);
 55         $labels['LastEdited'] = 'Время обновления';
 56         $labels['Duration'] = 'Продолжительность';
 57         $labels['TextStatus'] = 'Статус';
 58         return $labels;
 59     }
 60     
 61     function populateDefaults() {
 62         parent::populateDefaults();
 63         $this->StartTime = date('Y-m-d H:i:s');
 64         $this->Status = 'process';
 65         $this->StatusMessage = 'Начало импорта';
 66     }
 67     
 68     function getCMSFields() {
 69         $fields = new FieldSet();
 70         $fields->push(new LiteralField('LogTextResult', $this->renderWith('ProductImportLog')));        
 71         return $fields;
 72     }
 73     
 74     function RealLogItems() {       
 75         return DataObject::get('ProductImportLogItem', "LogID = {$this->ID}", 'ID', '', 50);
 76     }
 77     
 78     function addLog($message, $status='message') {      
 79         // иначе создается слишком много штук и админка вырубается
 80         if ($this->LogItems()->Count() < 1000) {
 81             $logItem = new ProductImportLog_Item();
 82             $logItem->LogID = $this->ID;
 83             $logItem->Message = $message;
 84             $logItem->Status = $status;
 85             $logItem->write();
 86         }   
 87 
 88         /*
 89         $this->Log .= $message . "\n";
 90         $this->write();
 91         */
 92     }
 93     
 94     function addStatus($type, $message) {
 95         if(ImportSiteConfig::$sendEmail){
 96             $data = array(
 97                 'type' => $type,
 98                 'message' => $message,
 99                 'StartTime' => $this->StartTime,
100                 'ID' => $this->ID,
101                 'Link' => "admin/import/ProductImportLog/{$this->ID}/edit"
102             );
103             $sc = SiteConfig::current_site_config();
104             foreach($sc->Notifications() as $item){
105                 // process,ok,error
106                 $data['Email'] = $item->Email;
107                 if($type == 'ok' && $item->Success){
108                     $this->sendLogEmail($data);
109                 }
110 
111                 if($type == 'error' && $item->Failure){
112                     $this->sendLogEmail($data);
113                 }
114             }
115         }
116         $this->Status = $type;
117         $this->StatusMessage = $message;        
118         //$this->TestLog .= date('Y-m-d H:m:s') . '|' . $type . '|' . $message . "\n";
119         $this->write();
120     }
121 
122     function sendLogEmail($data){
123         $statuses = array(
124             'ok' => 'Успешно',
125             'error' => 'Не завершен'
126         );
127         $statuses2 = array(
128             'ok' => 'успешно',
129             'error' => 'с ошибкой'
130         );
131         // "Импорт товаров от [дата, время]: Успешно / Не завершен"
132         // $data = array(
133         //  'type' => $type,
134         //  'message' => $message,
135         //  'StartTime' => $this->StartTime,
136         //  'ID' => $this->ID,
137         //  'Link' => Director::absoluteBaseURL()."admin/import/ProductImportLog/{$this->ID}/edit"
138         // );
139         $body = <<<EOF
140 Импорт товаров от {$data['StartTime']} завершен {$statuses2[$data['type']]}</br>
141 Лог импорта - <a href="{$data['Link']}">перейти</a>
142 EOF;
143 
144         $sc = SiteConfig::current_site_config();
145         $mail = new Email();
146         $mail->setFrom($sc->AdminEmail);
147         $mail->setSubject("Импорт товаров от {$data['StartTime']}: {$statuses[$data['type']]}");
148         $mail->setTo($data['Email']);
149         $mail->setBody($body);
150         $mail->send();
151     }
152     
153     function Duration() {
154         $end = $this->EndTime ? $this->EndTime : $this->LastEdited;
155 //      return strtotime($end) - strtotime($this->StartTime);
156         return gmdate('H:i:s', strtotime($end) - strtotime($this->StartTime));
157     }
158     
159     function TextStatus() {
160         return _t('ImportLog.Status_' . $this->Status, $this->Status);
161     }
162     
163     function onBeforeWrite() {
164         parent::onBeforeWrite();
165         if (!$this->EndTime && $this->Status != 'process') {
166             $this->EndTime = date('Y-m-d H:i:s');
167         }
168     }
169     
170     function onBeforeDelete() {
171         parent::onBeforeDelete();
172         
173         if ($this->LogItems()->Count()) {
174             foreach($this->LogItems() as $item) {
175                 $item->delete();
176             }
177         }
178     }
179     
180     function canEdit() {
181         return false;
182     }   
183 }
184 
185 class ProductImportLog_Item extends DataObject {
186     
187     static $db = array(     
188         'Status' => "Enum('message,warning,error')",
189         'Message' => 'Varchar(255)',        
190     );
191     
192     static $has_one = array(
193         'Log' => 'ProductImportLog'
194     );
195 
196 }
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.2 API Docs API documentation generated by ApiGen 2.8.0