示例#1
2
 /**
  * Download a specific law's card page.
  *
  * @param string $id          Law ID.
  * @param bool   $re_download Whether or not to re-download card page.
  *
  * @return Law
  * @throws JobChangePriorityException
  * @throws Exceptions\ProxyBanned
  */
 function downloadCard($id, $re_download = false)
 {
     /**
      * @var $law Law
      */
     $law = Law::find($id);
     try {
         $card = downloadCard($id, ['re_download' => $re_download || $this->re_download, 'check_related' => $law->status == Law::NOT_DOWNLOADED && !max_date()]);
     } catch (Exceptions\ProxyBanned $e) {
         throw $e;
     } catch (\Exception $e) {
         $message = str_replace('ShvetsGroup\\Service\\Exceptions\\', '', get_class($e)) . ($e->getMessage() ? ': ' . $e->getMessage() : '');
         throw new JobChangePriorityException($message, -15);
     }
     DB::transaction(function () use($law, $card) {
         $law->card = $card['card'];
         $law->title = $card['title'];
         $law->date = $card['date'];
         $law->setIssuers($card['meta'][Issuer::FIELD_NAME]);
         $law->setTypes($card['meta'][Type::FIELD_NAME]);
         $law->state = isset($card['meta'][State::FIELD_NAME]) ? reset($card['meta'][State::FIELD_NAME]) : State::STATE_UNKNOWN;
         $law->has_text = $card['has_text'] ? $law->has_text = Law::HAS_TEXT : ($law->has_text = Law::NO_TEXT);
         $has_unknown_revision = false;
         foreach ($card['revisions'] as &$revision) {
             if ($revision['date'] == '??.??.????') {
                 $has_unknown_revision = true;
                 continue;
             }
             $data = ['law_id' => $revision['law_id'], 'date' => $revision['date'], 'comment' => $revision['comment']];
             if ($law->notHasText() || isset($revision['no_text']) && $revision['no_text'] && $revision['date'] != $card['active_revision']) {
                 $data['status'] = Revision::NO_TEXT;
                 $data['text'] = '';
             }
             $r = Revision::findROrNew($data['law_id'], $data['date']);
             $r->save();
             $r->update($data);
         }
         // We should update revision which has just come into power.
         if ($law->active_revision && $law->active_revision != $card['active_revision']) {
             Revision::find($data['law_id'], $card['active_revision'])->update(['status' => Revision::NEEDS_UPDATE]);
         }
         $law->active_revision = $card['active_revision'];
         foreach ($law->revisions()->where('status', Revision::NEEDS_UPDATE)->get() as $revision) {
             $this->jobsManager->add('command.lawgrabber.download', 'downloadRevision', ['law_id' => $revision->law_id, 'date' => $revision->date], 'download', $revision->date == $law->active_revision ? 0 : -1);
         }
         if (isset($card['changes_laws']) && $card['changes_laws']) {
             Law::where('id', array_column($card['changes_laws'], 'id'))->update(['status' => Law::DOWNLOADED_BUT_HAS_UNKNOWN_REVISION]);
             foreach ($card['changes_laws'] as $l) {
                 $this->jobsManager->add('command.lawgrabber.download', 'downloadCard', ['id' => $l['id'], 're_download' => true], 'download', 2);
             }
         }
         $law->card_updated = $card['timestamp'];
         $law->status = $has_unknown_revision ? Law::DOWNLOADED_BUT_HAS_UNKNOWN_REVISION : Law::UP_TO_DATE;
         $law->save();
     });
     return $law;
 }
示例#2
0
 /**
  * Schedule crawls of each law list pages.
  *
  * @param null $starting_date If not passed or null, the 1991-01-01 will be taken as default.
  * @param bool $re_download Whether or not force re-download of the listings. Might be useful when updating recent days.
  */
 protected function addLawListJobs($starting_date = null, $re_download = false)
 {
     $this->jobsManager->deleteAll('discover');
     $date = strtotime($starting_date ?: '1991-01-01 00:00:00');
     $date = max($date, strtotime('1991-01-01 00:00:00'));
     if ($date <= strtotime('1991-01-01 00:00:00')) {
         $this->jobsManager->add('command.lawgrabber.discover', 'discoverDailyLawList', ['law_list_url' => '/laws/main/ay1990/page', 'date' => date('Y-m-d', $date)], 'discover');
     }
     while ($date <= strtotime('midnight') && (!max_date() || max_date() && $date < strtotime(max_date()))) {
         $this->jobsManager->add('command.lawgrabber.discover', 'discoverDailyLawList', ['law_list_url' => '/laws/main/a' . date('Ymd', $date) . '/sp5/page', 'date' => date('Y-m-d', $date), 're_download' => $re_download], 'discover', 5);
         $date = strtotime(date('c', $date) . '+1 day');
     }
 }
if (empty($user_ids_all_30_from_last_sms_expired)) {
    return;
}
//get details of all users expired. Filter this list to remove users that has meal time not the greatest. Remember: we only send mms to people having their last meal of the day his subscription expires
$users_expired_to_filter = $wpdb->get_results("SELECT User_ID, Field_Name, Field_Value FROM `wp_ewd_feup_user_fields` WHERE User_ID IN (" . implode(",", (array) $user_ids_all_30_from_last_sms_expired) . ") AND Field_Name IN ('Breakfast', 'Lunch', 'Dinner', 'Time zone') ORDER BY User_ID DESC", ARRAY_A);
$users_expired_to_filter_max_time = [];
foreach ($users_expired_to_filter as $u) {
    if ($u['Field_Name'] == "Time zone") {
        $users_expired_to_filter_max_time[$u['User_ID']]['time_zone'] = $u['Field_Value'];
    } else {
        $users_expired_to_filter_max_time[$u['User_ID']]['times'][] = $u['Field_Value'];
    }
}
$users_expired_to_filter = [];
foreach ($users_expired_to_filter_max_time as $id => $u) {
    $users_expired_to_filter[$id] = ['time_zone' => $u['time_zone'], 'max_date' => max_date($u['times'][0], $u['times'][1], $u['times'][2])];
}
foreach ($users_expired_to_filter as $id => $u) {
    $is_not_max = false;
    switch ($u['time_zone']) {
        case 'PST':
            if ($u['max_date'] !== $time_pst) {
                $is_not_max = true;
            }
            break;
        case 'EST':
            if ($u['max_date'] !== $time_est) {
                $is_not_max = true;
            }
            break;
        case 'MST':
    $diff = $date->diff(min_date());
    if (!$diff->invert) {
        return $GLOBALS['margin_left'];
    }
    return $GLOBALS['margin_left'] + $diff->days / (365.24 / $GLOBALS['year_width']);
}
$branches = branches_to_show();
$i = 0;
foreach ($branches as $branch => $version) {
    $branches[$branch]['top'] = $header_height + $branch_height * $i++;
}
if (!isset($non_standalone)) {
    header('Content-Type: image/svg+xml');
    echo '<?xml version="1.0"?>';
}
$years = iterator_to_array(new DatePeriod(min_date(), new DateInterval('P1Y'), max_date()));
$width = $margin_left + $margin_right + (count($years) - 1) * $year_width;
$height = $header_height + $footer_height + count($branches) * $branch_height;
?>
<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 <?php 
echo $width;
?>
 <?php 
echo $height;
?>
" width="<?php 
echo $width;
?>
" height="<?php 
echo $height;
?>