public function doSome() {
$str = date('Y-m-d H:i:s') . " - pid " . getmypid() . " - Start Cron\n";
$query = $this->db->query("SELECT some_data FROM " . DB_PREFIX . "some_table WHERE DATE(date_cancel) = CURDATE()");
if ($query->num_rows) {
foreach($query->rows as $result) {
$this->db->query("INSERT INTO " . DB_PREFIX . "some_table2 SET data = '" . (int)$result['data'] . "'");
$this->db->query("UPDATE " . DB_PREFIX . "some_table3 SET data = '" . (int)$result['data'] . "' WHERE data_id = '" . (int)$result['data_id'] . "'");
}
}
$str .= date('Y-m-d H:i:s') . " - pid " . getmypid() . " - End cron\n\n\n";
file_put_contents('/var/www/www-root/data/www/my-site,ru/system/logs/return.log', $str . "\r\n", FILE_APPEND | LOCK_EX);
}
добавление транзакции может привести к блокировкам и дедлокам при многопользовательской работе
public function addShipment($company_id, $point_id, $parcels) {
$this->db->query("INSERT INTO " . DB_PREFIX . "shipment SET company_id = '" . (int)$company_id . "', point_id = '" . (int)$point_id . "', quantity = '" . (int)count($parcels) . "', user = '" . $this->db->escape($this->admin->getFullname()) . "', date_added = NOW()");
$shipment_id = $this->db->getLastId();
// На момент этого запроса дынные о посылке уже присутствуют в базе данных и остаётся её только отгрузить присвоив номер перевозки shipment_id
$this->db->query("UPDATE " . DB_PREFIX . "shipment_parcel SET shipment_id = '" . (int)$shipment_id . "', date_modified = NOW() WHERE parcel_id IN (" . implode(',', $parcels) . ")");
//Изменяем состояние посылки
$this->db->query("UPDATE " . DB_PREFIX . "parcel SET shipment_id = '" . (int)$shipment_id . "', date_modified = NOW() WHERE parcel_id IN (" . implode(',', $parcels) . ")");
// Записываем статус в историю
foreach($parcels as $parcel_id) {
$this->db->query("INSERT INTO " . DB_PREFIX . "parcel_history SET parcel_id = '" . (int)$parcel_id . "', parcel_status_id = '" . (int)$this->config->get('config_expected_status') . "', user = '" . $this->db->escape($this->admin->getFullname()) . "', date_added = NOW()");
}
}
public function updateShipment($parcels) {
$this->db->query("UPDATE " . DB_PREFIX . "shipment_parcel SET date_delivery = NOW() WHERE point_id = '" . (int)$this->session->data['point_id'] . "' AND parcel_id IN (" . implode(',', $parcels) . ")");
$this->db->query("UPDATE " . DB_PREFIX . "parcel SET date_return = '" . $this->db->escape(date('Y-m-d', strtotime('+' . $this->config->get('config_parcel_deadline') .' days'))) . "', date_modified = NOW() WHERE point_id = '" . (int)$this->session->data['point_id'] . "' AND parcel_id IN (" . implode(',', $parcels) . ")");
foreach($parcels as $parcel_id) {
$this->db->query("INSERT INTO " . DB_PREFIX . "parcel_history SET parcel_id = '" . (int)$parcel_id . "', parcel_status_id = '" . (int)$this->config->get('config_recieved_status') . "', user = '" . $this->db->escape($this->operator->getFullname()) . "', date_added = NOW(), date_modified = NOW()");
}
}