Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
exchangelog.php
1<?php
2
4
7
24class ExchangeLogTable extends Main\Entity\DataManager
25{
26 public static function getTableName()
27 {
28 return 'b_sale_exchange_log';
29 }
30
31 public static function getMap()
32 {
33 return array(
34 'ID' => array(
35 'data_type' => 'integer',
36 'primary' => true,
37 'autocomplete' => true
38 ),
39 'ENTITY_ID' => array(
40 'required' => true,
41 'data_type' => 'integer'
42 ),
43 'ENTITY_TYPE_ID' => array(
44 'required' => true,
45 'data_type' => 'integer'
46 ),
47 'PARENT_ID' => array(
48 'data_type' => 'integer'
49 ),
50 'OWNER_ENTITY_ID' => array(
51 'data_type' => 'integer'
52 ),
53 'ENTITY_DATE_UPDATE' => array(
54 'data_type' => 'datetime',
55 ),
56 'XML_ID' => array(
57 'data_type' => 'string'
58 ),
59 'MARKED' => array(
60 'data_type' => 'boolean',
61 'values' => array('N', 'Y')
62 ),
63 'DESCRIPTION' => array(
64 'data_type' => 'text'
65 ),
66 'MESSAGE' => array(
67 'data_type' => 'text'
68 ),
69 'DATE_INSERT' => array(
70 'data_type' => 'datetime',
71 'require' => true,
72 'default_value' => function(){return new \Bitrix\Main\Type\DateTime();}
73 ),
74 'DIRECTION' => array(
75 'data_type' => 'string',
76 'require' => true,
77 'values' => array('E', 'I')
78 ),
79 'PROVIDER' => array(
80 'data_type' => 'string'
81 ),
82 );
83 }
84
88 public static function deleteAll()
89 {
90 $tableName = static::getTableName();
91 $connection = Main\Application::getConnection();
92 $connection->queryExecute("DELETE FROM {$tableName}");
93 }
94
98 public static function deleteOldRecords($direction, $provider, $interval)
99 {
100 $tableName = static::getTableName();
101
102 if ($direction == '')
103 throw new Main\ArgumentOutOfRangeException("$direction");
104 if ($provider == '')
105 throw new Main\ArgumentOutOfRangeException("$provider");
106
107 $r = ExchangeLogTable::getList(array(
108 'select' => array(
109 new Main\Entity\ExpressionField('MAX_DATE_INSERT', 'MAX(%s)', array('DATE_INSERT'))
110 ),
111 'filter' => array(
112 '=DIRECTION'=>$direction,
113 '=PROVIDER'=>$provider
114 )
115 ));
116
117 if ($loggingRecord = $r->fetch())
118 {
119 if($loggingRecord['MAX_DATE_INSERT'] <> '')
120 {
121 $maxDateInsert = $loggingRecord['MAX_DATE_INSERT'];
122 $date = new Main\Type\DateTime($maxDateInsert);
123 $connection = Main\Application::getConnection();
124 $connection->queryExecute("delete from {$tableName} where DATE_INSERT < DATE_SUB('{$date->format("Y-m-d")}', INTERVAL {$interval} DAY) and DIRECTION='{$direction}' and PROVIDER='{$provider}'");
125 }
126 }
127 }
128}
static deleteOldRecords($direction, $provider, $interval)