forked from vgrish/NewsModxBox
/
update.class.php
68 lines (49 loc) · 2.34 KB
/
update.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
Update comments thread
*/
abstract class modSocietyWebThreadsUpdateProcessor extends modObjectUpdateProcessor{
public $classKey = "SocietyThread";
public function initialize(){
// Sanitize post data
$this->unsetProperty('comments_count');
//$this->unsetProperty('createdon');
$this->unsetProperty('editedon');
if(!$thread_id = (int)$this->getProperty('thread_id')){
/*
Если не была получена ветка, то пытаемся ее создать
*/
if(
!$response = $this->modx->runProcessor('society/web/threads/get', array(
"target_id" => $this->getProperty("target_id"),
"target_class" => $this->getProperty("target_class", "modResource"),
), array(
"processors_path" => dirname(dirname(dirname(dirname(__FILE__)))) . '/',
)
)){
$error = "Ошибка выполнения запроса";
$this->modx->log(xPDO::LOG_LEVEL_ERROR, "[- ". __CLASS__ ." -] {$error}");
$this->modx->log(xPDO::LOG_LEVEL_ERROR, "[- ". __CLASS__ ." -] " . print_r($this->getProperties(), true));
return $error;
}
// else
if(
$response->isError()
OR !$thread_data = $response->getObject()
){
if(!$error = $response->getMessage()){
$error = "Не были получены данные ветви диалога";
}
$this->modx->log(xPDO::LOG_LEVEL_ERROR, "[- ". __CLASS__ ." -] {$error}");
$this->modx->log(xPDO::LOG_LEVEL_ERROR, "[- ". __CLASS__ ." -] " . print_r($response->getResponse(), true));
$this->modx->log(xPDO::LOG_LEVEL_ERROR, "[- ". __CLASS__ ." -] " . print_r($this->getProperties(), true));
return $error;
}
//else
$thread_id = $thread_data['id'];
}
$this->setProperty('id', $thread_id);
return parent::initialize();
}
}
return 'modSocietyWebThreadsUpdateProcessor';