Skip to content
This repository was archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ostiwe committed May 1, 2020
1 parent dc5cbbf commit 93ce4d8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
],
"require": {
"php": ">=7.1",
"vkcom/vk-php-sdk": "^5.101"
"vkcom/vk-php-sdk": "^5.101",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 9 additions & 8 deletions src/ostiwe-saver/Client/UserClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,25 @@ private function newMessageHandler($messageObj)
} catch (Exception $e) {
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/logs/markAsRead.log', $e->getMessage(), FILE_APPEND);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/logs/markAsRead.log', "\n==========\n", FILE_APPEND);
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}

try {
$attachments = $this->utilsPhoto->checkAttachments($this->userToken, $messageObj['attachments'], $likedOnly);
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}

try {
$attachmentsPathList = $this->utilsPhoto->downloadPhotoFromVk($this->userToken, $attachments);
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}

try {
$attachmentsList = $this->utilsPhoto->uploadWallPhotos($this->userToken, $groupId, $attachmentsPathList);
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}
$pubHandler->handle($attachmentsList, [
'interval' => $this->groups[$groupId]['post_interval']
Expand All @@ -219,7 +220,7 @@ public function uploadLocalFiles(array $filesList, $groupID)
try {
return $this->utilsPhoto->uploadWallPhotos($this->userToken, $groupID, $filesList);
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e->getMessage());
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

Expand All @@ -235,12 +236,12 @@ private function browserPluginHandler($eventObj)
try {
$downloadedPhoto = $this->utilsPhoto->downloadPhotoFromUri($eventObj['photo']);
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}
try {
$pubHandler = $this->loadMessageHandlerClasses($this->groups[$eventObj['group_id']]['name'] . 'Handler');
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}

if (empty($downloadedPhoto)) {
Expand All @@ -252,7 +253,7 @@ private function browserPluginHandler($eventObj)
try {
$uploadedPhoto = $this->utilsPhoto->uploadWallPhotos($this->userToken, $eventObj['group_id'], $downloadedPhoto);
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}

$pubHandler->handle($uploadedPhoto, [
Expand Down
36 changes: 25 additions & 11 deletions src/ostiwe-saver/Handlers/PubHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,28 @@ class PubHandler
{
/**
* Access user token
*
* @var string $userToken
* */
public $userToken = null;

/**
* User ID
*
* @var string|int $userId
* */
public $userId = null;

/**
* A community token allows working with API on behalf of a group, event or public page
*
* @var string $pubToken
* */
public $pubToken = null;

/**
* Pub ID
*
* @var string|int $pubId
* */
public $pubId = null;
Expand All @@ -65,10 +69,11 @@ class PubHandler

/**
* PubHandler constructor.
* @param string $userToken Access user token
* @param string|int $userId User ID
* @param string $pubToken A community token allows working with API on behalf of a group, event or public page
* @param string|int $pubId Group ID
*
* @param string $userToken Access user token
* @param string|int $userId User ID
* @param string $pubToken A community token allows working with API on behalf of a group, event or public page
* @param string|int $pubId Group ID
*/
public function __construct($userToken, $userId, $pubToken, $pubId)
{
Expand All @@ -89,9 +94,9 @@ public function __construct($userToken, $userId, $pubToken, $pubId)
/**
* Handler for this community
*
* @param array $attachmentsList Array of images uploaded to the server VK
* @param array $pubParams Parameters for the community. At this time, you need to set the interval
* @param string $postText The text of the post
* @param array $attachmentsList Array of images uploaded to the server VK
* @param array $pubParams Parameters for the community. At this time, you need to set the interval
* @param string $postText The text of the post
* @throws Exception
*/
public function handle(array $attachmentsList, array $pubParams, string $postText = '')
Expand All @@ -110,15 +115,24 @@ public function handle(array $attachmentsList, array $pubParams, string $postTex
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
}

return [
'pub_id' => $this->pubId,
'post_id' => $postInfo['post_id'],
'publish_date' => [
'unix' => $postInfo['date'],
'human' => $postDate
]
];
}

/**
* Gets the time of the last post and puts the post in the queue for publication.
* If there are no posts in the queue, the post will be published after the specified period.
*
* @param array $pubParams Parameters for the community. At this time, you need to set the interval
* @param array $attachmentsList Array of images uploaded to the server VK
* @param string $postText The text that will be attached to the post
* @param array $pubParams Parameters for the community. At this time, you need to set the interval
* @param array $attachmentsList Array of images uploaded to the server VK
* @param string $postText The text that will be attached to the post
* @return array Array containing the post id and the time of its publication
* @throws Exception
*/
Expand Down Expand Up @@ -165,7 +179,7 @@ public function post(array $pubParams, array $attachmentsList, $postText = '')
* Sends a notification message
*
* @param string $message
* @param array $attachments Array of images uploaded to the server VK
* @param array $attachments Array of images uploaded to the server VK
* @throws Exception
*/
public function sendNotificationMessage(string $message, array $attachments = [])
Expand Down

0 comments on commit 93ce4d8

Please sign in to comment.