_db->select(); $select->from($this->_getPair(), ['id']); $select->join($this->_getPair('LicenseTribe', 'lt'), '`lt`.`licenseId` = `l`.`id`', [ 'tribeId', 'expiredOn' => 'surchargeExpiredOn' ]); if (!($expiredOn = $this->getFilter('expiredOn'))) { throw new Exception('expiredOn dates are note defined'); }; $select->where('`lt`.`surcharge` IS NOT NULL'); $select->where('`lt`.`surchargeExpiredOn` IN(?)', $expiredOn); $select->where('`lt`.`status` = ?', Entity::TRIBE_STATUS_APPROVED); $select->order('lt.surchargeExpiredOn DESC'); return $select; } /** * @param $gracePeriod * @return int number of expired licenses * @throws \Zend_Db_Adapter_Exception */ public function disableExpired($gracePeriod) { $gracePeriod = (int) $gracePeriod; $date = date('Y-m-d', strtotime('-' . $gracePeriod . ' days')); $sql = 'UPDATE ' . Qs_Db::getPairExpr('LicenseTribe', 'lt') . ' ' . 'SET `lt`.`status` = ' . $this->_db->quote(Entity::TRIBE_STATUS_APPROVED_PENDING) . ', ' . ' `lt`.`changed` = NOW() ' . 'WHERE `lt`.`surcharge` IS NOT NULL ' . 'AND `lt`.`status` = ' . $this->_db->quote(Entity::TRIBE_STATUS_APPROVED) . ' ' . 'AND `lt`.`surchargeExpiredOn` <= ' . $this->_db->quote($date) . ' '; return $this->_db->exec($sql); } }