Пример #1
0
 /**
  * Carreful!! We delete WP elements here!
  * This is unreversible deletion, not trash!
  * @param integer $root_node
  * @return integer
  */
 private function delete_nodes($root_node)
 {
     $nb_deleted_nodes = 0;
     $this->nodes_data->load_multiple($root_node);
     $root_node_data = $this->nodes_data->get($root_node);
     if ($root_node_data !== null) {
         if ($root_node_data->type == 'page') {
             $nodes_to_delete = $this->apm_tree->get_nodes_flat($root_node);
             $this->nodes_data->load_multiple($nodes_to_delete, true, true);
             if (!empty($nodes_to_delete)) {
                 foreach ($nodes_to_delete as $node) {
                     $page_id = $this->nodes_data->get($node)->wp_id;
                     if ($this->nodes_data->get($node)->type == 'page') {
                         wp_delete_post($page_id, true);
                     }
                 }
                 $this->apm_tree->delete_sub_tree($root_node);
                 $this->nodes_data->delete($nodes_to_delete);
                 $this->tree_state->delete_nodes($nodes_to_delete);
                 //TODO: We should delete it from every users metas ???
                 $nb_deleted_nodes = count($nodes_to_delete);
                 $this->save();
             }
         }
     } else {
         //$root_node exists in APM tree but was not found in WP entities...
         //It must have been deleted from WP by some other way... but we still want
         //to delete it from our APM tree :
         $nodes_to_delete = $this->apm_tree->get_nodes_flat($root_node);
         if (!empty($nodes_to_delete)) {
             $this->apm_tree->delete_sub_tree($root_node);
             $this->tree_state->delete_nodes($nodes_to_delete);
             if (ApmAddons::addon_is_on('flagged_pages')) {
                 ApmMarkedNodes::delete_multiple($nodes_to_delete);
             }
             $nb_deleted_nodes = count($nodes_to_delete);
             $this->save();
         }
     }
     return $nb_deleted_nodes;
 }
Пример #2
0
 public function delete($nodes_to_delete)
 {
     if (is_numeric($nodes_to_delete)) {
         $nodes_to_delete = array($nodes_to_delete);
     }
     foreach ($nodes_to_delete as $k => $node) {
         if (!array_key_exists($node, $this->nodes_data)) {
             unset($nodes_to_delete[$k]);
         } else {
             unset($this->nodes_data[$node]);
         }
     }
     if (ApmAddons::addon_is_on('flagged_pages')) {
         ApmMarkedNodes::delete_multiple($nodes_to_delete);
     }
 }