Commit 9f66ae0e authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge branch 'develop' into selectchats_channels

parents 8f5f353a b6e13be0
......@@ -6,10 +6,14 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased]
### Added
- Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path).
- Allow setting a custom Guzzle HTTP Client for requests (#511).
### Changed
### Deprecated
### Removed
- [:exclamation:][unreleased-bc-up-download-directory] Upload and download directories are not set any more by default and must be set manually.
### Fixed
- ID fields are now typed with `PARAM_STR` PDO data type, to allow huge numbers.
- Message type data type for PDO corrected.
### Security
## [0.44.1] - 2017-04-25
......@@ -25,7 +29,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Removed
- All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot).
### Fixed
- [:exclamation:](https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#0440) Format of Update content type using `$update->getUpdateContent()`.
- [:exclamation:][0.44.0-bc-update-content-type] Format of Update content type using `$update->getUpdateContent()`.
## [0.43.0] - 2017-04-17
### Added
......@@ -100,3 +104,6 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Logging improvements to Botan integration.
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.
[unreleased-bc-up-download-directory]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[0.44.0-bc-update-content-type]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#update-getupdatecontent
......@@ -63,8 +63,8 @@ class DebugCommand extends AdminCommand
$debug_info = [];
$debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath());
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath() ?: '`_Not set_`');
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath() ?: '`_Not set_`');
// Commands paths.
$debug_info[] = '*Commands paths:*';
......
......@@ -201,7 +201,7 @@ class DB
$sth->bindParam(':limit', $limit, PDO::PARAM_INT);
if ($id !== null) {
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->bindParam(':id', $id, PDO::PARAM_STR);
}
$sth->execute();
......@@ -327,13 +327,13 @@ class DB
(:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id, :edited_message_id)
');
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_INT);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_INT);
$sth->bindParam(':id', $id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_STR);
$sth->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, PDO::PARAM_STR);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_STR);
$sth->bindParam(':edited_message_id', $edited_message_id, PDO::PARAM_STR);
return $sth->execute();
} catch (PDOException $e) {
......@@ -375,7 +375,7 @@ class DB
`updated_at` = VALUES(`updated_at`)
');
$sth->bindParam(':id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':username', $username, PDO::PARAM_STR, 255);
$sth->bindParam(':first_name', $first_name, PDO::PARAM_STR, 255);
$sth->bindParam(':last_name', $last_name, PDO::PARAM_STR, 255);
......@@ -398,8 +398,8 @@ class DB
(:user_id, :chat_id)
');
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$status = $sth->execute();
} catch (PDOException $e) {
......@@ -449,14 +449,14 @@ class DB
if ($migrate_to_chat_id) {
$chat_type = 'supergroup';
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $chat_id, PDO::PARAM_STR);
} else {
$sth->bindParam(':id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_STR);
}
$sth->bindParam(':type', $chat_type, PDO::PARAM_INT);
$sth->bindParam(':type', $chat_type, PDO::PARAM_STR);
$sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255);
$sth->bindParam(':username', $chat_username, PDO::PARAM_STR, 255);
$sth->bindParam(':all_members_are_administrators', $chat_all_members_are_administrators, PDO::PARAM_INT);
......@@ -616,8 +616,8 @@ class DB
$query = $inline_query->getQuery();
$offset = $inline_query->getOffset();
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR);
$sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
......@@ -665,7 +665,7 @@ class DB
$query = $chosen_inline_result->getQuery();
$sth->bindParam(':result_id', $result_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':query', $query, PDO::PARAM_STR);
......@@ -733,10 +733,10 @@ class DB
$inline_message_id = $callback_query->getInlineMessageId();
$data = $callback_query->getData();
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':callback_query_id', $callback_query_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $user_id, PDO::PARAM_STR);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
$sth->bindParam(':data', $data, PDO::PARAM_STR);
$sth->bindParam(':created_at', $date, PDO::PARAM_STR);
......@@ -868,13 +868,13 @@ class DB
$migrate_to_chat_id = $message->getMigrateToChatId();
$pinned_message = $message->getPinnedMessage();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':date', $date, PDO::PARAM_STR);
$sth->bindParam(':forward_from', $forward_from, PDO::PARAM_INT);
$sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_INT);
$sth->bindParam(':forward_from_message_id', $forward_from_message_id, PDO::PARAM_INT);
$sth->bindParam(':forward_from', $forward_from, PDO::PARAM_STR);
$sth->bindParam(':forward_from_chat', $forward_from_chat, PDO::PARAM_STR);
$sth->bindParam(':forward_from_message_id', $forward_from_message_id, PDO::PARAM_STR);
$sth->bindParam(':forward_date', $forward_date, PDO::PARAM_STR);
$reply_to_chat_id = null;
......@@ -882,8 +882,8 @@ class DB
$reply_to_chat_id = $chat_id;
}
$sth->bindParam(':reply_to_chat', $reply_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':reply_to_message', $reply_to_message_id, PDO::PARAM_INT);
$sth->bindParam(':reply_to_chat', $reply_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':reply_to_message', $reply_to_message_id, PDO::PARAM_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR);
$sth->bindParam(':audio', $audio, PDO::PARAM_STR);
......@@ -896,16 +896,16 @@ class DB
$sth->bindParam(':contact', $contact, PDO::PARAM_STR);
$sth->bindParam(':location', $location, PDO::PARAM_STR);
$sth->bindParam(':venue', $venue, PDO::PARAM_STR);
$sth->bindParam(':new_chat_member', $new_chat_member, PDO::PARAM_INT);
$sth->bindParam(':left_chat_member', $left_chat_member, PDO::PARAM_INT);
$sth->bindParam(':new_chat_member', $new_chat_member, PDO::PARAM_STR);
$sth->bindParam(':left_chat_member', $left_chat_member, PDO::PARAM_STR);
$sth->bindParam(':new_chat_title', $new_chat_title, PDO::PARAM_STR);
$sth->bindParam(':new_chat_photo', $new_chat_photo, PDO::PARAM_STR);
$sth->bindParam(':delete_chat_photo', $delete_chat_photo, PDO::PARAM_INT);
$sth->bindParam(':group_chat_created', $group_chat_created, PDO::PARAM_INT);
$sth->bindParam(':supergroup_chat_created', $supergroup_chat_created, PDO::PARAM_INT);
$sth->bindParam(':channel_chat_created', $channel_chat_created, PDO::PARAM_INT);
$sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, PDO::PARAM_INT);
$sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, PDO::PARAM_INT);
$sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, PDO::PARAM_STR);
$sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, PDO::PARAM_STR);
$sth->bindParam(':pinned_message', $pinned_message, PDO::PARAM_STR);
return $sth->execute();
......@@ -964,9 +964,9 @@ class DB
$text = $edited_message->getText();
$caption = $edited_message->getCaption();
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_INT);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_INT);
$sth->bindParam(':chat_id', $chat_id, PDO::PARAM_STR);
$sth->bindParam(':message_id', $message_id, PDO::PARAM_STR);
$sth->bindParam(':user_id', $from_id, PDO::PARAM_STR);
$sth->bindParam(':edit_date', $edit_date, PDO::PARAM_STR);
$sth->bindParam(':text', $text, PDO::PARAM_STR);
$sth->bindParam(':entities', $entities, PDO::PARAM_STR);
......
......@@ -104,16 +104,32 @@ class Request
*
* @param \Longman\TelegramBot\Telegram $telegram
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws TelegramException
*/
public static function initialize(Telegram $telegram)
{
if (is_object($telegram)) {
if (!($telegram instanceof Telegram)) {
throw new TelegramException('Invalid Telegram pointer!');
}
self::$telegram = $telegram;
self::$client = new Client(['base_uri' => self::$api_base_uri]);
} else {
throw new TelegramException('Telegram pointer is empty!');
self::setClient(new Client(['base_uri' => self::$api_base_uri]));
}
/**
* Set a custom Guzzle HTTP Client object
*
* @param Client $client
*
* @throws TelegramException
*/
public static function setClient(Client $client)
{
if (!($client instanceof Client)) {
throw new TelegramException('Invalid GuzzleHttp\Client pointer!');
}
self::$client = $client;
}
/**
......@@ -262,8 +278,12 @@ class Request
*/
public static function downloadFile(File $file)
{
if (empty($download_path = self::$telegram->getDownloadPath())) {
throw new TelegramException('Download path not set!');
}
$tg_file_path = $file->getFilePath();
$file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path;
$file_path = $download_path . '/' . $tg_file_path;
$file_dir = dirname($file_path);
//For safety reasons, first try to create the directory, then check that it exists.
......
......@@ -161,10 +161,6 @@ class Telegram
$this->bot_username = $bot_username;
}
//Set default download and upload path
$this->setDownloadPath(BASE_PATH . '/../Download');
$this->setUploadPath(BASE_PATH . '/../Upload');
//Add default system commands path
$this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment