/**
  * Up
  **/
 public function up()
 {
     // include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     // Load some objects
     $wishlist = new \Components\Wishlist\Tables\Wishlist($this->db);
     $wish = new \Components\Wishlist\Tables\Wish($this->db);
     // Get records
     $lists = $wishlist->getRecords(array('category' => 'group'));
     // vars to hold counts
     $deletedLists = 0;
     $deletedWishes = 0;
     // check to make sure each group wishlist has a valid group
     foreach ($lists as $list) {
         // load group
         $group = \Hubzero\User\Group::getInstance($list->referenceid);
         // if group doesnt exist we need to remove the list and wishes
         if (!$group || !is_object($group)) {
             // Get wishes
             $wishes = $wish->get_wishes($list->id, array('filterby' => 'all', 'sortby' => ''), 1);
             // delete each wish
             foreach ($wishes as $item) {
                 $wish->load($item->id);
                 $wish->delete();
                 $deletedWishes++;
             }
             // delete wishlist
             $wishlist->load($list->id);
             $wishlist->delete();
             $deletedLists++;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Delete any associated wishes & lists when group is deleted
  * 
  * @param      object $group Group being deleted
  * @return     string Log of items removed
  */
 public function onGroupDelete($group)
 {
     // include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     // Load some objects
     $database = App::get('db');
     $wishlist = new \Components\Wishlist\Tables\Wishlist($database);
     $wish = new \Components\Wishlist\Tables\Wish($database);
     // Get wishlist id
     $id = $wishlist->get_wishlistID($group->get('gidNumber'), 'group');
     // no id means no list
     if (!$id) {
         return '';
     }
     // Get wishes
     $wishes = $wish->get_wishes($id, array('filterby' => 'all', 'sortby' => ''), 1);
     // delete each wish
     foreach ($wishes as $item) {
         $wish->load($item->id);
         $wish->delete();
     }
     // delete wishlist
     $wishlist->load($id);
     $wishlist->delete();
     // return message
     return Lang::txt('PLG_GROUPS_WISHLIST_LOG', count($wishes));
 }