Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
retypos-server
Commits
4e191350
Commit
4e191350
authored
Sep 07, 2018
by
Георгий Попов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Задача 12799] Добавил метод для получения ссылки редактирования статьи
Добавил в модель новый метод, который у адаптера запрашивает ссылку на редактирование статьи, имея ссылку на опечатку
parent
ec0f6ac4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
13 deletions
+64
-13
Typo.php
cp/application/models/Typo.php
+64
-13
No files found.
cp/application/models/Typo.php
View file @
4e191350
...
@@ -314,6 +314,68 @@ class Typo extends CI_Model {
...
@@ -314,6 +314,68 @@ class Typo extends CI_Model {
}
}
/**
/**
* По заданной ссылке на статью возвращает ссылку на адаптер сайта
*
* @param string $link Ссылка на статью
* @return string URL адаптера JSON RPC
*/
private
function
getTyposAdapterUrl
(
string
$link
)
{
$correctPath
=
$this
->
config
->
item
(
"correction_path"
);
/* Получаем адрес необходимого сайта */
$parsed_url
=
parse_url
(
$link
);
// Адрес на который шлем запрос исправления
return
$parsed_url
[
"scheme"
]
.
"://"
.
$parsed_url
[
"host"
]
.
"/"
.
$correctPath
;
}
/**
* Creates and returns a connection with adapter by JSON RPC protocol
*
* @param string $adapterUrl Url on which an adapter listen
* @return \JsonRPC\Client Connection with an adapter
*/
function
createConnectionWithAdapter
(
string
$adapterUrl
)
{
$user
=
$this
->
config
->
item
(
"typos_user"
);
$password
=
$this
->
config
->
item
(
"typos_password"
);
$client
=
new
\JsonRPC\Client
(
$adapterUrl
);
$client
->
getHttpClient
()
->
withDebug
()
->
withUsername
(
$user
)
->
withPassword
(
$password
);
return
$client
;
}
/**
* Отправляет запрос к адаптеру на получение ссылки на редактирование
* статьи.
*
* @param int $messageId
*
* @throws Exception Если что-либо пошло не так
* @return string URL редактирования статьи или же null в случае ошибки
*/
public
function
getArticleEditUrl
(
int
$messageId
)
{
$this
->
db
->
select
(
"link"
);
$this
->
db
->
from
(
"messages"
);
$this
->
db
->
where
(
"id"
,
$messageId
);
$link
=
$this
->
db
->
get
()
->
row
()
->
link
;
$url
=
$this
->
getTyposAdapterUrl
(
$link
);
$client
=
$this
->
createConnectionWithAdapter
(
$url
);
$editLink
=
$client
->
getEditLink
(
$link
);
if
(
!
isset
(
$editLink
[
"errorCode"
])
||
$editLink
[
"errorCode"
]
!=
200
)
{
throw
new
Exception
(
$editLink
[
"message"
],
$editLink
[
"errorCode"
]);
}
return
$editLink
[
"message"
];
}
/**
* Отправляет запрос к клиентскому серверу на автоматическое
* Отправляет запрос к клиентскому серверу на автоматическое
* исправление опечатки. Сервер клиента должен использовать
* исправление опечатки. Сервер клиента должен использовать
* библиотеку etersoft/typos_client.
* библиотеку etersoft/typos_client.
...
@@ -325,10 +387,6 @@ class Typo extends CI_Model {
...
@@ -325,10 +387,6 @@ class Typo extends CI_Model {
* @throws Exception Если произошла ошибка
* @throws Exception Если произошла ошибка
*/
*/
function
correctTypo
(
int
$typoId
,
string
$corrected
)
{
function
correctTypo
(
int
$typoId
,
string
$corrected
)
{
$correctPath
=
$this
->
config
->
item
(
"correction_path"
);
$user
=
$this
->
config
->
item
(
"typos_user"
);
$password
=
$this
->
config
->
item
(
"typos_password"
);
/* Получаем исправление */
/* Получаем исправление */
$this
->
db
->
select
(
"m.link as link, m.text as text, m.comment as comment, m.context as context"
);
$this
->
db
->
select
(
"m.link as link, m.text as text, m.comment as comment, m.context as context"
);
$this
->
db
->
from
(
"messages as m"
);
$this
->
db
->
from
(
"messages as m"
);
...
@@ -336,17 +394,10 @@ class Typo extends CI_Model {
...
@@ -336,17 +394,10 @@ class Typo extends CI_Model {
$correction
=
$this
->
db
->
get
()
->
row
();
$correction
=
$this
->
db
->
get
()
->
row
();
/* Получаем адрес необходимого сайта */
$url
=
$this
->
getTyposAdapterUrl
(
$correction
->
link
);
$parsed_url
=
parse_url
(
$correction
->
link
);
// Адрес на который шлем запрос исправления
$url
=
$parsed_url
[
"scheme"
]
.
"://"
.
$parsed_url
[
"host"
]
.
"/"
.
$correctPath
;
try
{
try
{
$client
=
new
\JsonRPC\Client
(
$url
);
$client
=
$this
->
createConnectionWithAdapter
(
$url
);
$client
->
getHttpClient
()
->
withDebug
()
->
withUsername
(
$user
)
->
withPassword
(
$password
);
$result
=
$client
->
fixTypo
(
$correction
->
text
,
$corrected
,
$correction
->
context
,
$correction
->
link
);
$result
=
$client
->
fixTypo
(
$correction
->
text
,
$corrected
,
$correction
->
context
,
$correction
->
link
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment