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

  • CliController
  • CorrectBadFoldersTask
  • DailyTask
  • DeleteEmptyAssociatedFoldersTask
  • FillTechTitleTask
  • FindCyrillic
  • HourlyTask
  • MonthlyTask
  • PostVKNotificationQueueTask
  • QuarterHourlyTask
  • RealtyXMLImportTask
  • ScheduledTask
  • WeeklyTask
  • YearlyTask
 1 <?php
 2 // задача отправки сообщений через АПИ Вконтакте из очереди сообщений.
 3 // после каждой отправки - пауза 0,5 секунды (по требованиям АПИ)
 4 class PostVKNotificationQueueTask extends ScheduledTask {
 5     function process() {        
 6         // чтобы новый импорт не запускался, если старый еще работает
 7         $pidFile = TEMP_FOLDER . '/vk_post.pid';
 8         if (is_file($pidFile)) {
 9             $pid = (int) file_get_contents($pidFile);           
10             if (posix_getsid($pid) !== false) {
11                 // импорт уже работает             
12                 return;
13             } else {                
14                 unlink($pidFile);
15             }
16         }
17         file_put_contents($pidFile, getmypid());        
18         
19         $messagesToPost = DataObject::get('VKNotificationQueue', 'Posted = 0');     
20         if ($messagesToPost) {
21             $conf = SiteConfig::current_site_config();
22             if ($conf->ClientNotificationVKAccessToken) {
23                 $url = 'https://api.vk.com/method/messages.send';
24                 foreach($messagesToPost as $entry) {
25                     $params = array(
26                         'user_id' => $entry->UserID,    // Кому отправляем
27                         'message' => $entry->Message,   // Что отправляем
28                         'access_token' => $conf->ClientNotificationVKAccessToken,  // access_token можно вбить хардкодом, если работа будет идти из под одного юзера
29                         'v' => '5.37',
30                     );
31                     // В $result вернется id отправленного сообщения
32                     $result = file_get_contents($url, false, stream_context_create(array(
33                         'http' => array(
34                             'method'  => 'POST',
35                             'header'  => 'Content-type: application/x-www-form-urlencoded',
36                             'content' => http_build_query($params)
37                         )
38                     )));
39                     $rs = json_decode($result);
40                     if (isset($rs->response) && (int)$rs->response) {
41                         $entry->Posted = 1;
42                         $entry->write();
43                     }
44                     // засыпаем на полсекунды
45                     usleep(500000);
46                 }
47             }
48         }
49     }
50 }
[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