Example #1
0
    protected function processAction()
    {
        $writer = new Zend_Log_Writer_Stream('php://stdout');
        $logger = new Zend_Log($writer);
        $settings = Settings::getInstance();
        try {
            $view = $this->application->getBootstrap()->getResource('view');
            $view->setScriptPath(APPLICATION_PATH . '/views/scripts');
            $adapter = Zend_Db_Table::getDefaultAdapter();
            $stmt = $adapter->query(<<<SQL
        SELECT id,
            (CASE WHEN awaits_from is null THEN created_at
           ELSE awaits_from END)  "awaits_from",
               customer_considering, closing_time FROM negotiations.negotiation_step WHERE closing_time is null AND created_at > '2013-08-01'::date
SQL
);
            //
            $toProcess = $stmt->fetchAll();
            $logger->info('Found ' . count($toProcess) . ' ongoing negotiations.');
            $errs = 0;
            $to_exp = 0;
            $now = date('Y-m-d', time());
            $model = new NegotiationStep();
            $adapter->query(<<<SQL
              ALTER TABLE negotiations.negotiation_step DISABLE TRIGGER negotiation_step_last_update_refresh
SQL
);
            foreach ($toProcess as $nid) {
                if ($nid['customer_considering'] == 'true' || $nid['customer_considering'] == 'TRUE' || $nid['customer_considering'] == 't') {
                    switch ('working') {
                        case 'working':
                            $date = @Logic_DateUtils::getDateByWorkingDays(5, $nid['awaits_from']) . ' 23:59:59';
                            break;
                        case 'calendar':
                            $date = date('Y-m-d', strtotime($nid['awaits_from'] . ' +' . 5 . ' days')) . ' 23:59:59';
                            break;
                        default:
                            throw new Exception('Misconfiguration in negotiations.settings table');
                    }
                } else {
                    switch ('working') {
                        case 'working':
                            $date = @Logic_DateUtils::getDateByWorkingDays(5, $nid['awaits_from']) . ' 23:59:59';
                            break;
                        case 'calendar':
                            $date = date('Y-m-d', strtotime($nid['awaits_from'] . ' +' . 5 . ' days')) . ' 23:59:59';
                            break;
                        default:
                            throw new Exception('Misconfiguration in negotiations.settings table');
                    }
                }
                $to_exp++;
                try {
                    $model->update(array('closing_time' => $date), 'id = \'' . $nid['id'] . '\'');
                } catch (Exception $e) {
                    $errs++;
                }
                echo $to_exp . "\t" . $errs . "\n";
            }
            $adapter->query(<<<SQL
              ALTER TABLE negotiations.negotiation_step ENABLE TRIGGER negotiation_step_last_update_refresh
SQL
);
            if ($errs == 0) {
                $logger->info('Successfuly expired all qualifying negotiations (' . $to_exp . ')');
            } else {
                $logger->warn('Negotiations qualifying for expiration processed with errors. ' . $errs . '/' . count($to_exp) . ' failed. Check previous log messages for details.');
            }
        } catch (Exception $e) {
            $logger->crit($e->getMessage());
        }
        $logger->info('Script executed succesfully');
        exit(0);
    }
Example #2
0
 public function getExitrationDate($considering = FALSE, $start = null)
 {
     if ($start === null) {
         $start = date('Y-m-d H:i:s', time());
     }
     $start = explode(' ', $start);
     if (@Logic_DateUtils::isWorkingDay($start[0])) {
         $work = -1;
     } else {
         $work = 0;
     }
     if ($considering !== FALSE) {
         switch ($this->get('dsk_decision_validity_days_type')) {
             case 'working':
                 return @Logic_DateUtils::getDateByWorkingDays($this->get('dsk_decision_validity_days') + $work, $start[0]) . " 23:59:59";
                 break;
             case 'calendar':
                 return date('Y-m-d', strtotime($start[0] . ' + ' . ($this->get('dsk_decision_validity_days') - 1) . ' days')) . ' ' . $start[1];
                 break;
             default:
                 throw new Exception('No time utils present in database', '00');
         }
     } else {
         switch ($this->get('no_response_dsk_decision_validity_days_type')) {
             case 'working':
                 return @Logic_DateUtils::getDateByWorkingDays($this->get('no_response_dsk_decision_validity_days') + $work, $start[0]) . " 23:59:59";
                 break;
             case 'calendar':
                 return date('Y-m-d', strtotime($start[0] . ' + ' . ($this->get('no_response_dsk_decision_validity_days') - 1) . ' days')) . ' ' . $start[0];
                 break;
             default:
                 throw new Exception('No time utils present in database', '00');
         }
     }
 }