From 8454f623134b07329dda5954ccbb953bc4c13d6b Mon Sep 17 00:00:00 2001 From: gponty Date: Tue, 28 Nov 2023 11:07:12 +0100 Subject: [PATCH] =?UTF-8?q?Passage=20=C3=A0=20la=20version=202023-10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 +++++++------ src/MondayApi.php | 38 ++++++++++++++++++-------------------- src/MondayBundle.php | 2 -- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d42b157..fad1444 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Symfony Monday Api This is a Symfony 6 Bundle helps you to use monday API v2 : https://developer.monday.com/apps/docs/mondayapi. +It use version 2023-10. ## Installation @@ -14,7 +15,6 @@ This is a Symfony 6 Bundle helps you to use monday API v2 : https://developer.mo ``` shell MONDAY_API_KEY=your_token - MONDAY_API_VERSION=2023-07 ``` @@ -23,7 +23,6 @@ This is a Symfony 6 Bundle helps you to use monday API v2 : https://developer.mo ``` shell monday: api_key: '%env(MONDAY_API_KEY)%' - api_version: '%env(MONDAY_API_VERSION)%' ``` @@ -46,10 +45,12 @@ Use the service : groups { id title - items(limit: 100, page:1) { - id - name - } + items_page(limit: 100, page:1) { + cursor + items{ + id + name + } } } }'; diff --git a/src/MondayApi.php b/src/MondayApi.php index d2b81e5..07dddb3 100644 --- a/src/MondayApi.php +++ b/src/MondayApi.php @@ -4,7 +4,7 @@ class MondayApi { - public function __construct(private readonly string $mondayApiKey, private readonly string $mondayApiVersion) + public function __construct(private readonly string $mondayApiKey) { } @@ -22,7 +22,7 @@ public function request(string $query, array $variables = []): bool|array $headers = [ 'Content-Type: application/json', 'User-Agent: Github.com/symfony-monday-api', - 'API-Version: '.$this->mondayApiVersion, + 'API-Version: 2023-10', 'Authorization: '.$this->mondayApiKey, ]; @@ -110,7 +110,7 @@ public function createGroup(int $boardId, string $groupTitle): string|bool } /** - * Create new item if not exists. + * Create new item if not exists, key is column name. * * @param int $boardId Monday board id * @param string $groupId Monday group id @@ -122,15 +122,21 @@ public function createGroup(int $boardId, string $groupTitle): string|bool public function createItem(int $boardId, string $groupId, string $itemName, array $itemValues): string|bool { // On insere ou update dans Monday - // On recuperer tous les items et groupes pour checker que l'item existe ou pas + // On check si l'item existe ou pas $query = '{ boards(ids: '.$boardId.') { id name - groups(ids: '.$groupId.') { + groups(ids: "'.$groupId.'") { id title - items {id name} + items_page(query_params: {rules: [{column_id: "name", compare_value: ["'.$itemName.'"]}], operator: and}){ + cursor + items { + id + name + } + } } } } @@ -139,25 +145,15 @@ public function createItem(int $boardId, string $groupId, string $itemName, arra if (false === $responseContent) { return false; } - if (!isset($responseContent['boards'][0]['groups'][0]['items']) || !\is_array($responseContent['boards'][0]['groups'][0]['items'])) { + if (!isset($responseContent['boards'][0]['groups'][0]['items_page']['items']) || !\is_array($responseContent['boards'][0]['groups'][0]['items_page']['items'])) { return false; } - $items = $responseContent['boards'][0]['groups'][0]['items']; + $items = $responseContent['boards'][0]['groups'][0]['items_page']['items']; - // On créé les domaines qui n'existent pas + // On créé les items qui n'existent pas // et on met à jour ceux qui existent - $trouve = false; - $itemId = 0; - - foreach ($items as $item) { - if ($item['name'] === $itemName) { - $trouve = true; - $itemId = $item['id']; - break; - } - } - if (!$trouve) { + if (\count($items) === 0) { $query = 'mutation { create_item(board_id: '.$boardId.', group_id: "'.$groupId.'", item_name: "'.$itemName.'") { id @@ -172,6 +168,8 @@ public function createItem(int $boardId, string $groupId, string $itemName, arra return false; } $itemId = $data['create_item']['id']; + } else { + $itemId = $items[0]['id']; } // On met à jour diff --git a/src/MondayBundle.php b/src/MondayBundle.php index a214c79..d87635e 100644 --- a/src/MondayBundle.php +++ b/src/MondayBundle.php @@ -16,7 +16,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C $container->services() ->get(MondayApi::class) ->arg('$mondayApiKey', $config['api_key']) - ->arg('$mondayApiVersion', $config['api_version']) ; } @@ -26,7 +25,6 @@ public function configure(DefinitionConfigurator $definition): void $definition->rootNode() ->children() ->scalarNode('api_key')->defaultValue('%env(MONDAY_API_KEY)%')->end() - ->scalarNode('api_version')->defaultValue('%env(MONDAY_API_VERSION)%')->end() ->end() ; }