# كيفية استخدام مهمة ريك المخصصة 'undo change timestamp'؟

**URL:** https://meta.discourse.org/t/how-to-use-undo-change-timestamp-custom-rake-task/309450
**Category:** Development
**Created:** [26 مايو 2024، 9:47ص UTC](https://meta.discourse.org/t/how-to-use-undo-change-timestamp-custom-rake-task/309450 "2024-05-26T09:47:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Dotila\_Li](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dotila_li/32/303426_2.png) [@Dotila\_Li](https://meta.discourse.org/u/Dotila_Li)
#### Post date: [26 مايو 2024، 9:47ص UTC](https://meta.discourse.org/t/how-to-use-undo-change-timestamp-custom-rake-task/309450/1 "2024-05-26T09:47:31Z")

</div>

> [@Undo change timestamp](https://meta.discourse.org/t/undo-change-timestamp/78966):
>
> One of our mods changed the timestamp as a way to unbump a topic and I wanted to revert that change because. I wrote a rake task that does this. It’s a small thing, but why not share? # /var/www/discourse/lib/tasks/set\_timestamp\_to\_last\_version.rake desc "Set timestamp of all posts in a topic to the post's last\_version\_at" task "set\_timestamp\_to\_last\_version", [:topic\_id] =\> :environment do |\_, args| topic\_id = args[:topic\_id] if !topic\_id puts "ERROR: Expecting rake set\_timestamp\_to\_la…

كيف يمكن تشغيل هذا بالتفصيل؟ أنا لست على دراية بمهمة rake.

لقد واجهت هذه المشكلة:

```plaintext
-bash: cd: /var/www/discourse: No such file or directory

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [26 مايو 2024، 11:46ص UTC](https://meta.discourse.org/t/how-to-use-undo-change-timestamp-custom-rake-task/309450/2 "2024-05-26T11:46:40Z")

</div>

تحتاج إلى القيام بذلك داخل الحاوية.

```plaintext
cd /var/discourse
./launcher enter app

```

إذا كان بإمكانك القيام بذلك من واجهة المستخدم بدلاً من ذلك كما تقترح إحدى المشاركات أعلاه، فهذا ما أوصي به.

تحتاج أيضًا إلى إنشاء ملف بهذا الرمز بداخله، باستخدام nano، ربما.

---

<div class="post-metadata">

### Author: ![Dotila\_Li](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dotila_li/32/303426_2.png) [@Dotila\_Li](https://meta.discourse.org/u/Dotila_Li)
#### Post date: [26 مايو 2024، 11:54ص UTC](https://meta.discourse.org/t/how-to-use-undo-change-timestamp-custom-rake-task/309450/3 "2024-05-26T11:54:13Z")

</div>

شكراً لك، سأجرب ذلك لاحقاً.

لقد جربت طريقة الـ API للتو.

> **[Discourse API Docs](https://docs.discourse.org/#tag/Topics/operation/updateTopicTimestamp)**

ولكنني أحصل على خطأ 400، يقول:

```plaintext
{ errors: ['param is missing or the value is empty: timestamp'] }

```

هذا هو الكود الخاص بي:

```js
changeTimestamp(935, 1694291380);

async function changeTimestamp(topicId, timestamp) {
  const endpoint = `/t/${topicId}/change-timestamp`;
  const payload = {
    timestamp: timestamp,
  };
  put(endpoint, payload);
}

async function put(endpoint, payload) {
  const response = await fetch(DISCOURSE_ADDRESS + endpoint, {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
      "Api-Key": DISCOURSE_API_KEY,
      "Api-Username": API_USERNAME,
      body: JSON.stringify(payload),
    },
  });
  const result = await response.json();
  if (!response.ok) {
    console.log("put failed");
    console.log(result);
  } else {
    console.log("put success");
  }
}

```

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [26 مايو 2024، 12:43م UTC](https://meta.discourse.org/t/how-to-use-undo-change-timestamp-custom-rake-task/309450/4 "2024-05-26T12:43:08Z")

</div>

> [@Dotila\_Li](#):
>
> ```plaintext
> headers: {
> "Content-Type": "application/json",
> "Api-Key": DISCOURSE_API_KEY,
> "Api-Username": API_USERNAME,
> body: JSON.stringify(payload),
> },
> 
> ```

لقد وضعت `body` داخل `headers`. إنها ليست ترويسة بل خيار. انظر التوثيق أدناه:

> **[Using the Fetch API - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options)**
>
> The Fetch API provides a JavaScript interface for making HTTP requests and processing the responses.
