protected function _parsePages()
{
Webflow::setToken($this->webflow_api_token);
- dd(Webflow::listPages($this->webflow));
+ dd(Webflow::getAllData($this->webflow));
}
public function getLocales()
*/
public function mirror($slow = true, $force = false)
{
+ Webflow::setToken($this->webflow_api_token);
+ Webflow::clearCache();
+ Webflow::getAllData($this->webflow);
+
$path = $this->getMirrorPath();
if ($force) {
$path = Files::emptyDir($path);
return $response->json()['access_token'];
}
- public static function request($url, $data = [], $method = 'get', $ttl = 600, $force = false)
+ public static function request($url, $data = [], $method = 'get', $ttl = 86400, $force = false)
{
$cacheKey = 'webflow_' . static::getToken() . '_' . $method . '_' . $url . '_' . sha1(print_r($data, true));
if ($force) {
Cache::forget($cacheKey);
}
- $res = Cache::tags('webflow')->remember($cacheKey, $ttl, function () use ($url, $method, $data) {
+ $res = Cache::tags('webflow_' . static::getToken())->remember($cacheKey, $ttl, function () use ($url, $method, $data) {
+ while (Cache::get('webflow_' . static::getToken() . '_wait', false)) {
+ sleep(1);
+ }
/** @var Response $response */
$response = Http::withToken(self::getToken())->$method(self::BASE_URL . $url, $data);
- if ((int)$response->header('X-RateLimit-Remaining') <= 2) {
+ if ((int)$response->header('X-RateLimit-Remaining') <= 1) {
+ Cache::set('webflow_' . static::getToken() . '_wait', true, 60);
sleep(60);
}
return $response->json();
public static function clearCache()
{
- return Cache::tags('webflow')->flush();
+ return Cache::tags('webflow_' . static::getToken())->flush();
}
public static function listSites()
{
$res = [];
foreach (self::listPages($shortname) as $page) {
- $res[$page['id']] = self::getPageContents($page['id']);
+ $res[$page['id']] = [
+ 'details' => $page,
+ 'contents' => self::getPageContents($page['id'])
+ ];
}
+ return $res;
+ }
+
+ public static function getAllCMSContents($shortname)
+ {
+ $res = [];
+ foreach (self::listCMSCollections($shortname) as $collection) {
+ $res[$collection['id']] = [
+ 'details' => self::getCMSCollectionDetails($collection['id']),
+ 'contents' => self::getCMSCollectionContents($collection['id']),
+ ];
+ }
+
+ return $res;
+ }
+
+ public static function getAllData($shortname)
+ {
+ return ['pages' => self::getAllPagesContents($shortname), 'cms' => self::getAllCMSContents($shortname)];
+ }
+
+ public static function getCMSCollectionDetails($collectionID)
+ {
+ return self::request('collections/' . $collectionID);
+ }
+
+ public static function getCMSCollectionContents($collectionID)
+ {
+ return self::request('collections/' . $collectionID . '/items')['items'];
+ }
+
+ public static function listCMSCollections($shortname)
+ {
+ return self::request('sites/' . self::getSiteId($shortname) . '/collections')['collections'];
}
public static function getPageContents($pageID)