Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Darkscribes Community

  1. Home
  2. Uncategorized
  3. How to mass edit post content?

How to mass edit post content?

Scheduled Pinned Locked Moved Uncategorized
4 Posts 3 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • laz@community.nodebb.orgL This user is from outside of this forum
    laz@community.nodebb.orgL This user is from outside of this forum
    [email protected]
    wrote last edited by
    #1

    Heya everyone. Not long ago our forum migrated to NodeBB using the old migration tool. As part of that we changed all the old bb style [code] blocks, but I made a mistake when doing it and there are a bunch of blocks that use [c] as an alias for [code].

    How do I mass edit all posts, replacing "[c]" with "\n```\n"? I am more than happy to use the mongo shell if that's an option.

    ~ Laz

    baris@community.nodebb.orgB laz@community.nodebb.orgL 2 Replies Last reply
    0
    • laz@community.nodebb.orgL [email protected]

      Heya everyone. Not long ago our forum migrated to NodeBB using the old migration tool. As part of that we changed all the old bb style [code] blocks, but I made a mistake when doing it and there are a bunch of blocks that use [c] as an alias for [code].

      How do I mass edit all posts, replacing "[c]" with "\n```\n"? I am more than happy to use the mongo shell if that's an option.

      ~ Laz

      baris@community.nodebb.orgB This user is from outside of this forum
      baris@community.nodebb.orgB This user is from outside of this forum
      [email protected]
      wrote last edited by
      #2

      The below custom script should do what you need. Make a backup of your database and place the script in your nodebb folder. Then you can run it with nodeb script_name.js

      /* eslint-disable no-await-in-loop */
      /* globals require, console, process */
      
      'use strict';
      
      const nconf = require('nconf');
      
      nconf.file({
      	file: 'config.json',
      });
      
      nconf.defaults({
      	base_dir: __dirname,
      	views_dir: './build/public/templates',
      	upload_path: 'public/uploads',
      });
      
      const db = require('./src/database');
      
      db.init(async (err) => {
      	if (err) {
      		console.log(`NodeBB could not connect to your database. Error: ${err.message}`);
      		process.exit();
      	}
      
      	await fixPosts();
      	console.log('done');
      	process.exit();
      });
      
      
      async function fixPosts() {
      	const batch = require('./src/batch');
      	await batch.processSortedSet('posts:pid', async (pids) => {
      		const postData = await db.getObjects(pids.map(pid => `post:${pid}`));
      		const bulkSet = [];
      		postData.forEach(p => {
      			if (p && p.content) {
      				bulkSet.push([
      					`post:${p.pid}`,
      					{
      						content: String(p.content).replace(/\[c\]/g, '\n```\n'),
      					},
      				])
      			}
      		});
      
      		await db.setObjectBulk(bulkSet);
      	}, {
      		batch: 500,
      	});
      }
      
      1 Reply Last reply
      0
      • laz@community.nodebb.orgL [email protected]

        Heya everyone. Not long ago our forum migrated to NodeBB using the old migration tool. As part of that we changed all the old bb style [code] blocks, but I made a mistake when doing it and there are a bunch of blocks that use [c] as an alias for [code].

        How do I mass edit all posts, replacing "[c]" with "\n```\n"? I am more than happy to use the mongo shell if that's an option.

        ~ Laz

        laz@community.nodebb.orgL This user is from outside of this forum
        laz@community.nodebb.orgL This user is from outside of this forum
        [email protected]
        wrote last edited by
        #3

        Much appreciated! I'll give that a run later tonight.

        I am a little confused about how to run the script though. Is nodeb a typo for nodebb? If it is, I don't think i can run commands via ./nodebb [script], I just get error: unknown command as a response. If it's not a typo, what is it?

        Many thanks.

        julian@community.nodebb.orgJ 1 Reply Last reply
        0
        • laz@community.nodebb.orgL [email protected]

          Much appreciated! I'll give that a run later tonight.

          I am a little confused about how to run the script though. Is nodeb a typo for nodebb? If it is, I don't think i can run commands via ./nodebb [script], I just get error: unknown command as a response. If it's not a typo, what is it?

          Many thanks.

          julian@community.nodebb.orgJ This user is from outside of this forum
          julian@community.nodebb.orgJ This user is from outside of this forum
          [email protected]
          wrote last edited by
          #4

          @Laz it was a typo, you can run the script with node script_name.js, which invokes the node.js interpreter.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups