منشورات Rake:remap - لم يتم إعادة تعيين أي منشورات!

أحاول البحث عن صور معطلة متبقية من هجرتنا من المنتدى إلى Discourse واستبدالها، وقد حققت نجاحًا كبيرًا (أحب أمر remap!) لكنه لا يجد أي شيء لاستبداله في هذه الأمثلة، ولا أستطيع رؤية أي خطأ، هل يمكنك ذلك؟

محتوى المثال:

<img src="https://londonbikers.com/images/transparent.png" alt="PICT0738.JPG" data-orig-src="upload://1yz82u6bbkaAQ7xP06qNTmX9qy3.JPG" width="666" height="500" class="d-lazyload">

و

<img src="https://londonbikers.com/images/transparent.png" alt="Rhonda.JPG" data-orig-src="upload://vXQ67D17QssTe5cu6lamJ5XB5Ep.JPG" width="590" height="500" class="d-lazyload">

أحتاج إلى القيام بذلك في مرحلتين لأنني أحتاج إلى الاحتفاظ بمحتوى وسم alt وإعادة بناء عنصر img حوله. يفشل الأمر في عملية remap الأولى:

أي البحث عن:
<img src="https://londonbikers.com/images/transparent.png" alt="

والاستبدال بـ:
<img src="https://londonbikersarchive.blob.core.windows.net/forum-attachments/

لقد افترضت أن علامات الاقتباس المزدوجة تحتاج إلى الهروب باستخدام شرطة مائلة للخلف؟ لذا استخدمت هذا الأمر:

rake posts:remap["<img src=\"https://londonbikers.com/images/transparent.png\" alt=\"","<img src=\"https://londonbikersarchive.blob.core.windows.net/forum-attachments/"]

لكنني أُخبر أن 0 منشورات تم إعادة تعيينها! بينما هناك الآلاف من المنشورات التي تحتوي على هذه العناصر. أي أفكار؟

ستكون مرحلتي الثانية هي إعادة تعيين نهاية الوسم من:
width="666" height="500" class="d-lazyload">

إلى:
/>

Oh, hang on, some of these images are working. Is this Discourse attachment functionality? Is there some custom rendering logic going on as opposed to these being HTML strings in the database?

For example, this is showing a photo:

<img src="https://londonbikers.com/uploads/default/original/1X/25b381a9dc03f023a1c5d0af4f2f3132dfbf45c7.jpg" alt="The_rides_0010.jpg" width="640" height="480" class="d-lazyload">

But this one doesn’t. I can have the file in cloud blob storage so would either like to import it into Discourse or just have it referenced from blob storage:

<img src="https://londonbikers.com/images/transparent.png" alt="__2.jpg" data-orig-src="upload://411oUp2Yn6wumJCRAiFptkwTF58.jpg" width="662" height="500" class="d-lazyload">

Are those images in raw?

I think that rather than doing it with remap you’ll be better off using ruby in the rails console.

I’m sorry I didn’t understand any of that Jay :slight_smile:

Raw, like the file format? No just usual web formats. Doing what in rails console?

raw is the field where the text you see in the editor is. The stuff you are replacing is what you see if you edit the post in the ux, right? (cooked is the stuff that’s been processed and is what gets displayed.)

Doing stuff to re-write the posts. This is might be just enough to make you dangerous:

bps = Post.where("raw like '%//SOME-STRING%'")
bps.each do |post|
  post.raw.gsub!(/OLD/,'NEW')
  post.save
end

The advantage over the rake task is that you don’t have multiple levels of espaping to navigate.

إعجابَين (2)