Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with domains when publishing a site. #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/Webflow/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ private function request(string $path, string $method, array $data = [])
}
curl_setopt_array($curl, $options);
$response = curl_exec($curl);
curl_close($curl);

list($headers, $body) = explode("\r\n\r\n", $response, 2);

$body = mb_substr($response, curl_getinfo($curl, CURLINFO_HEADER_SIZE));
curl_close($curl);

return $this->parse($body);
}
private function get($path)
Expand Down Expand Up @@ -117,7 +121,9 @@ public function domains(string $siteId)

public function publishSite(string $siteId, array $domains)
{
return $this->post("/sites/${siteId}/publish", $domains);
return $this->post("/sites/${siteId}/publish", [
'domains' => $domains
]);
}

// Collections
Expand Down Expand Up @@ -204,6 +210,39 @@ public function findOrCreateItemByName(string $collectionId, array $fields)
$this->cacheSet($cacheKey, $items);
return $newItem;
}

public function createOrUpdateItemByName(string $collectionId, array $fields)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jbardnz and thanks for the PR. Domains fix looks good, but createOrUpdateItemByName is a custom logic of your application. Could you please, take it out, so we can merge the rest.

{
if (!isset($fields['name'])) {
throw new WebflowException('name');
}

$items = $this->itemsAll($collectionId);

if(count($items) == 0){
throw new WebflowException('No items found');
}

foreach ($items as $item) {
if (strcasecmp($item->name, $fields['name']) === 0) {

//Add required fields
if(!array_key_exists('slug', $fields)){
$fields['slug'] = $item->slug;
}

//Update existing item
$this->updateItem($collectionId, $item->_id, $fields);
return $item;
}
}

//Create a new item
$newItem = $this->createItem($collectionId, $fields);

return $newItem;
}


private function cache($key, callable $callback)
{
Expand Down