wiki/server/models/pages.js
/**
   * Delete an Existing Page
   *
   * @param {Object} opts Page Properties
   * @returns {Promise} Promise with no value
   */
Delete an Existing Page
@param {Object} opts Page Properties
@returns {Promise} Promise with no value
Delete an Existing Page @param { Object } opts Page Properties @returns { Promise } Promise with no value
static async deletePage(opts) {
    let page
    if (_.has(opts, 'id')) {
      page = await WIKI.models.pages.query().findById(opts.id)
    } else {
      page = await WIKI.models.pages.query().findOne({
        path: opts.path,
        localeCode: opts.locale
      })
    }
    if (!page) {
      throw new Error('Invalid Page Id')
    }
    if (!WIKI.auth.checkAccess(opts.user, ['delete:pages'], {
      locale: page.locale,
      path: page.path
    })) {
      throw new WIKI.Error.PageDeleteForbidden()
    }
    await WIKI.models.pageHistory.addVersion({
      ...page,
      action: 'deleted',
      versionDate: page.updatedAt
    })
    await WIKI.models.pages.query().delete().where('id', page.id)
    await WIKI.models.pages.deletePageFromCache(page.hash)
    WIKI.events.outbound.emit('deletePageFromCache', page.hash)
    await WIKI.models.pages.rebuildTree()
    await WIKI.data.searchEngine.deleted(page)
    if (!opts.skipStorage) {
      await WIKI.models.storage.pageEvent({
        event: 'deleted',
        page
      })
    }
    await WIKI.models.pages.reconnectLinks({
      locale: page.localeCode,
      path: page.path,
      mode: 'delete'
    })
  }
static async deletePage ( opts ) { let page if ( _ . has ( opts , 'id' ) ) { page = await WIKI . models . pages . query ( ) . findById ( opts . id ) } else { page = await WIKI . models . pages . query ( ) . findOne ( { path : opts . path , localeCode : opts . locale } ) } if ( ! page ) { throw new Error ( 'Invalid Page Id' ) } if ( ! WIKI . auth . checkAccess ( opts . user , [ 'delete:pages' ] , { locale : page . locale , path : page . path } ) ) { throw new WIKI . Error . PageDeleteForbidden ( ) } await WIKI . models . pageHistory . addVersion ( { ... page , action : 'deleted' , versionDate : page . updatedAt } ) await WIKI . models . pages . query ( ) . delete ( ) . where ( 'id' , page . id ) await WIKI . models . pages . deletePageFromCache ( page . hash ) WIKI . events . outbound . emit ( 'deletePageFromCache' , page . hash ) await WIKI . models . pages . rebuildTree ( ) await WIKI . data . searchEngine . deleted ( page ) if ( ! opts . skipStorage ) { await WIKI . models . storage . pageEvent ( { event : 'deleted' , page } ) } await WIKI . models . pages . reconnectLinks ( { locale : page . localeCode , path : page . path , mode : 'delete' } ) }
Delete an Existing Page
 @param {Object} opts Page Properties
 @returns {Promise} Promise with no value
Delete an Existing Page @param { Object } opts Page Properties @returns { Promise } Promise with no value
// -> Check for page access // -> Create version snapshot // -> Delete page // -> Rebuild page tree // -> Delete from Search Index // -> Delete from Storage // -> Reconnect Links