GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 834310...97aa84 )
by gyeong-won
08:57
created

syndicationController::triggerMoveDocumentModule()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 35
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 19
nc 7
nop 1
dl 0
loc 35
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * @class  syndicationController
6
 * @author NAVER ([email protected])
7
 * @brief syndication module's Controller class
8
 **/
9
10
class syndicationController extends syndication
11
{
12
	var $ping_message = '';
13
14 View Code Duplication
	function triggerInsertDocument(&$obj) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
		if($obj->module_srl < 1) return $this->makeObject();
16
		if($obj->status !== 'PUBLIC') return $this->makeObject();
17
18
		$oSyndicationModel = getModel('syndication');
19
		$oModuleModel = getModel('module');
20
21
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
22
23
		$config = $oModuleModel->getModuleConfig('syndication');
24
25
		if($config->syndication_use!='Y') return $this->makeObject();
26
27
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
28
		$id = $oSyndicationModel->getID('article', $target_id);
29
		$this->ping($id, 'article');
30
31
		return $this->makeObject();
32
	}
33
34 View Code Duplication
	function triggerUpdateDocument(&$obj) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
		if($obj->module_srl < 1) return $this->makeObject();
36
37
		$oSyndicationModel = getModel('syndication');
38
		$oModuleModel = getModel('module');
39
40
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
41
42
		$config = $oModuleModel->getModuleConfig('syndication');
43
44
		if($config->syndication_use!='Y') return $this->makeObject();
45
46
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
47
		$id = $oSyndicationModel->getID('article', $target_id);
48
49
		// PUBLIC 외 삭제
50
		if($obj->status === 'PUBLIC')
51
		{
52
			$this->ping($id, 'article');
53
		}
54
		else
55
		{
56
			$this->ping($id, 'deleted');
57
		}
58
59
		return $this->makeObject();
60
	}
61
62
	function triggerDeleteDocument(&$obj) {
63
		if($obj->module_srl < 1) return $this->makeObject();
64
65
		$oModuleModel = getModel('module');
66
		$oSyndicationModel = getModel('syndication');
67
68
		$config = $oModuleModel->getModuleConfig('syndication');
69
		if($config->syndication_use != 'Y') return $this->makeObject();
70
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
71
72
		$this->insertLog($obj->module_srl, $obj->document_srl, $obj->title, $obj->content);
73
74
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
75
		$id = $oSyndicationModel->getID('article', $target_id);
76
		$this->ping($id, 'deleted');
77
78
		return $this->makeObject();
79
	}
80
81
	// @DEPRECATED
82
	function triggerDeleteModule(&$obj) {
0 ignored issues
show
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
		return $this->makeObject();
84
	}
85
86
	function triggerMoveDocumentModule(&$obj)
87
	{
88
		if($obj->module_srl < 1) return $this->makeObject();
89
90
		$oSyndicationModel = getModel('syndication');
91
		$oModuleModel = getModel('module');
92
93
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
94
95
		$config = $oModuleModel->getModuleConfig('syndication');
96
97
		if($config->syndication_use!='Y') return $this->makeObject();
98
99
		$arr_document_srl = explode(',', $obj->document_srls);
100
		if(!$arr_document_srl) return $this->makeObject();
0 ignored issues
show
Bug Best Practice introduced by
The expression $arr_document_srl of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
101
102
		foreach($arr_document_srl as $document_srl)
103
		{
104
			// 기존 문서 삭제
105
			$source_module_srl = $obj->source_module_srl[$document_srl];
106
			if(!!$source_module_srl)
107
			{
108
				$target_id = sprintf('%s-%s', $source_module_srl, $document_srl);
109
				$id = $oSyndicationModel->getID('article', $target_id);
110
				$this->ping($id, 'deleted');
111
			}
112
113
			// 옮겨진 문서 추가
114
			$target_id = sprintf('%s-%s', $obj->module_srl, $document_srl);
115
			$id = $oSyndicationModel->getID('article', $target_id);
116
			$this->ping($id, 'article');
117
		}
118
119
		return $this->makeObject();
120
	}
121
122
	function triggerMoveDocumentToTrash(&$obj) {
123
		$oSyndicationModel = getModel('syndication');
124
		$oModuleModel = getModel('module');
125
126
		if($oSyndicationModel->isExceptedModules($obj->module_srl)) return $this->makeObject();
127
128
		$config = $oModuleModel->getModuleConfig('syndication');
129
130
		if($config->syndication_use!='Y') return $this->makeObject();
131
132
		$this->insertLog($obj->module_srl, $obj->document_srl, '', '');
133
134
		$target_id = sprintf('%s-%s', $obj->module_srl, $obj->document_srl);
135
		$id = $oSyndicationModel->getID('article', $target_id);
136
		$this->ping($id, 'deleted');
137
138
		return $this->makeObject();
139
	}
140
141
	// @deprecated
142
	function triggerRestoreTrash(&$obj) {
0 ignored issues
show
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
143
		// 중복 전송으로 인해 중단
144
		return $this->makeObject();
145
	}
146
147
	function insertLog($module_srl, $document_srl, $title = null, $summary = null)
148
	{
149
		$args = new stdClass;
150
		$args->module_srl = $module_srl;
151
		$args->document_srl = $document_srl;
152
		$args->title = $title;
153
		$args->summary = $summary;
154
		$output = executeQuery('syndication.insertLog', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
155
	}
156
157
	function deleteLog($module_srl, $document_srl)
158
	{
159
		$args = new stdClass;
160
		$args->module_srl = $module_srl;
161
		$args->document_srl = $document_srl;
162
		$output = executeQuery('syndication.deleteLog', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
163
	}
164
165
	function ping($id, $type, $page=1) {
166
		$this->ping_message = '';
167
		$oSyndicationModel = getModel('syndication');
168
169
		$oModuleModel = getModel('module');
170
		$config = $oModuleModel->getModuleConfig('syndication');
171
172
		if(!$config->syndication_token)
173
		{
174
			$this->ping_message = 'Syndication Token empty';
175
			$oSyndicationModel->setResentPingLog($this->ping_message);
176
			return false;
177
		}
178
179
		if(!$this->checkOpenSSLSupport())
180
		{
181
			$lang = Context::get('lang');
182
			$this->ping_message = $lang->msg_need_openssl_support;
183
			$oSyndicationModel->setResentPingLog($this->ping_message);
184
			return false;
185
		}
186
187
		if(substr($config->site_url,-1)!='/')
188
		{
189
			$config->site_url .= '/';
190
		}
191
192
		$ping_url = 'https://apis.naver.com/crawl/nsyndi/v2';
193
		$ping_header = array();
194
		$ping_header['Host'] = 'apis.naver.com';
195
		$ping_header['Pragma'] = 'no-cache';
196
		$ping_header['Accept'] = '*/*';
197
		$ping_header['Authorization'] = sprintf("Bearer %s", $config->syndication_token);
198
199
		$request_config = array();
200
		$request_config['ssl_verify_peer'] = false;
201
202
		$ping_body = getNotEncodedFullUrl('', 'module', 'syndication', 'act', 'getSyndicationList', 'id', $id, 'type', $type, 'page', $page, 'syndication_password', $config->syndication_password);
203
204
		$buff = FileHandler::getRemoteResource($ping_url, null, 10, 'POST', 'application/x-www-form-urlencoded', $ping_header, array(), array('ping_url'=>$ping_body), $request_config);
205
206
		$xml = new XmlParser();
207
		$xmlDoc= $xml->parse($buff);
208
209
		if($xmlDoc->result->error_code->body != '000')
210
		{
211
			if(!$buff)
212
			{
213
				$this->ping_message = 'Socket connection error. Check your Server Environment.';
214
			}
215
			else
216
			{
217
				$this->ping_message = $xmlDoc->result->message->body;
218
			}
219
220
			$oSyndicationModel->setResentPingLog($this->ping_message);
221
			return false;
222
		}
223
		return true;
224
	}
225
}
226