douchun1859 2016-12-01 15:19
浏览 24
已采纳

SilverStripe正确删除代码页面

This seems to be a difficult area in SS.

I'm trying to delete a page by code using: $page->doArchive();

This however, leaves a ghost of the page in the SiteTree menu with an option to "restore draft". This however breaks the functionality of my module and is not desired at all.

How do you completely remove a page so that user cannot see / recover it?

EDIT: Also tried:

DB::query("DELETE FROM SomePage WHERE ForeignID = {$this->ID}");
DB::query("DELETE FROM SomePage_Live WHERE ForeignID = {$this->ID}");
DB::query("DELETE FROM SomePage_versions WHERE ForeignID = {$this->ID}");

And even cleared the MySQL Table manually (phpmyadmin) and STILL there it shows the page (crossed out in menu) with a restore draft option.

EDIT2: This piece of messy code will delete all records and remove the ability to restore a draft. However, the deleted page icon is still shown in the sitetree and will dissappear after a refresh.

DB::query("DELETE FROM SomePage WHERE ForeignID = {$this->ID}");
DB::query("DELETE FROM SomePage_Live WHERE ForeignID = {$this->ID}");
DB::query("DELETE FROM SomePage_versions WHERE ForeignID = {$this->ID}");
DB::query("DELETE FROM SomePage_versions WHERE ForeignID = 0");

DB::query("DELETE FROM SiteTree WHERE ID = {$pageID}");
DB::query("DELETE FROM SiteTree_Live WHERE ID = {$pageID}");
DB::query("DELETE FROM SiteTree_versions WHERE RecordID = {$pageID}");

Question: How do prevent the "flash" of deleted page icon?

  • 写回答

1条回答 默认 最新

  • doukanxi4246 2016-12-01 21:22
    关注

    SilverStripe doesn't delete, it uses archive, which you can do via $page->doArchive();. I think if you're writing a module, you should definitely use this way of deleting pages, as it's what somebody would expect. Unless your module is about completely removing records from the Database…

    If you really need to clean up the Database and want to do things manually, you also need to hook into the site-tree JavaScript (entwine), so that it will properly refresh the site-tree once you delete a page.

    Update:

    Here's a small piece of code how you could force an update on some or all tree nodes.

    Create a custom entwine script, let's save it at mysite/javascript/tree-hook.js

    (function($) {
        $(function(){
            // ss.tree "namespace" is needed to be able to access the tree methods
            $.entwine('ss.tree', function($){
                // Match your custom button selector
                $(".myCustomButton").entwine({
                    onmatch: function () {
                        this._super();
                        // bind a namespaced click handler (for easy removal)
                        $(this).on("click.treeHook", function (e) {
                            e.preventDefault();
                            e.stopImmediatePropagation();
                            // pass in all the tree node IDs you need to update
                            $(".cms-tree").updateNodesFromServer([/* IDs */]);
                        });
                    },
                    onunmatch: function () {
                        this._super();
                        $(this).off("click.treeHook");
                    }
                })
            });
        });
    })(jQuery);
    

    Then load in the custom JS into the CMS by adding the following to your config.yml:

    LeftAndMain:
      extra_requirements_javascript:
        - 'mysite/javascript/tree-hook.js'
    

    For more information about entwine, consider looking at this beginners guide or the github repository

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料