public function handle()
{
+ start_measure('Webflow Publish '.$this->id.' '.$this->mode);
/** @var ToolWebflow $wf */
$wf = ToolWebflow::withoutGlobalScopes()->find($this->id);
$subject = __('Site :name publié', ['name' => $wf->name]);
if ($this->mode === 'webflow') {
- $wf->mirror(false, rand(1, 10) === 10);
+ $wf->refreshFormDataFromAPI();
+ $wf->mirror(false);
$text = __('Le site vient d\'être républié suite à une mise à jour de webflow');
} else if ($this->mode === 'auto') {
$text = __('Le site vient d\'être républié suite à une mise à jour des contenus');
$actions[__('Visiter [:locale]', ['locale' => $locale['locale']])] = 'https://' . $locale['url'];
}
if ($this->user === null) {
- // Slack::send($wf->slack, $subject, $text, $actions, false);
+ // Slack::send($wf->slack, $subject, $text, $actions, false);
} else {
$this->user->notify(new ToolboxNotification($subject, $text, $actions, true));
}
+ stop_measure('Webflow Publish '.$this->id.' '.$this->mode);
}
}
}
$seo = $this->getTranslations('seo');
$images = $this->getTranslations('images');
+ $locales = $this->getLocalesCodes();
+ $translateAPI = new Api(env('AZURE_TRANSLATE_API_KEY'));
$hasChanged = false;
+ $imagesChanged = false;
foreach ($seo[$mainLocale] as $page) {
}
foreach ($images[$mainLocale] as $id => $alt) {
- if ($api['images'][$id] !== $alt) {
- $api['images'][$id] = $alt;
+ $apiAlt = $api['images'][$id]['alt'] ?? str_starts_with($api['images'][$id]['alt'], '__wf_') ? '' : $api['images'][$id]['alt'];
+ if ($apiAlt != $alt) {
+ $api['images'][$id]['alt'] = $alt;
Webflow::saveImageAlt($id, $alt);
+ $hasChanged = true;
+ }
+
+ if ($alt) {
+ foreach ($locales as $locale) {
+ if ($locale === $mainLocale) {
+ continue;
+ }
+ if (!$images[$locale][$id]) {
+ $images[$locale][$id] = $translateAPI->translate($alt, $locale, $mainLocale);
+ $imagesChanged = true;
+ $hasChanged = true;
+ }
+ }
}
}
if ($hasChanged) {
$this->api = json_encode($api);
+ if ($imagesChanged) {
+ $this->setTranslations('images', $images);
+ }
$this->saveQuietly();
}
return Cache::lock('webflow_api_refresh_' . $this->id);
}
- protected function refreshFormDataFromAPI()
+ public function refreshFormDataFromAPI()
{
+ start_measure("Webflow refresh data from api");
$lock = $this->getLock();
try {
- $lock->block(360);
+ // $lock->block(360);
Webflow::clearCache();
$this->api = Webflow::getEditableData($this->webflow);
} catch (LockTimeoutException $e) {
} finally {
- $lock?->release();
+ $lock?->forceRelease();
}
+
+ stop_measure("Webflow refresh data from api");
}
/**
*/
public function mirror($slow = true, $force = false)
{
+ start_measure('Webflow mirror');
+
Webflow::setToken($this->webflow_api_token);
- $this->refreshFormDataFromAPI();
$path = $this->getMirrorPath();
if ($force) {
}
$wget->setArg(null, 'https://' . $this->webflow . '.webflow.io');
$wget->execute();
+
+ stop_measure('Webflow mirror');
return $wget;
}
$lock = $this->getLock();
try {
- $lock->block(1200);
+ $lock->block(360);
$locales = $this->locales_domains;
if (is_string($locales)) {
} catch (LockTimeoutException $e) {
} finally {
- $lock?->release();
+ $lock?->forceRelease();
}
public static function request($url, $data = [], $method = 'get', $ttl = 86400, $force = false)
{
+ start_measure('Webflow API : ' . $url);
$cacheKey = self::getCacheKey($url, $data, $method);
if ($force) {
Cache::forget($cacheKey);
if (null === $res && !$force) {
return self::request($url, $data, $method, $ttl, true);
}
+ stop_measure('Webflow API : ' . $url);
return $res;
}
public static function saveImageAlt($id, $alt)
{
-
+ return self::request('assets/' . $id, ['altText' => $alt], 'post', 0, true);
}
public static function getEditableData($shortname)
{
+ start_measure('Webflow : get editable data');
+
$key = self::getToken() . '_' . $shortname;
if (!isset(self::$_editableData[$key])) {
$data = self::getAllData($shortname);
if (isset($res['images'][$assetId])) {
continue;
}
- $res['images'][$pageID . '_' . $assetId] = ['page' => $pageID, 'id' => $assetId, 'alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']];
+ $res['images'][$assetId] = ['page' => $pageID, 'id' => $assetId, 'alt' => $node['image']['alt'], 'url' => $data['assets'][$assetId]['hostedUrl']];
}
}
}
self::$_editableData[$key] = $res;
}
+
+ stop_measure('Webflow : get editable data');
return self::$_editableData[$key];
}
}
<th>Texte alternatif</th>
</tr>
@foreach($images as $id=>$image)
+ @if(is_string($image))
+ @continue
+ @endif
@php
+
$e=explode('/',$image['url']);
$ee=array_pop($e);
$e=explode('_',$ee,2);