/** 
  * Delete the provided item from the database
  *
  * @param Saveable $item
  * @return bool
  * 
  */
 public function ___delete(Saveable $item)
 {
     $database = $this->wire('database');
     $lookupTable = $database->escapeTable($this->getLookupTable());
     $table = $database->escapeTable($this->getTable());
     $item_id = (int) $item->id;
     $query = $database->prepare("DELETE FROM {$lookupTable} WHERE {$table}_id=:item_id");
     // QA
     $query->bindValue(":item_id", $item_id, PDO::PARAM_INT);
     $query->execute();
     return parent::___delete($item);
 }
示例#2
0
 /**
  * Create and return a cloned copy of the given Field
  *
  * @param Field|Saveable $item Item to clone
  * @return bool|Saveable $item Returns the new clone on success, or false on failure
  * @throws WireException
  *
  */
 public function ___clone(Saveable $item)
 {
     $item = $item->type->cloneField($item);
     // don't clone system flags
     if ($item->flags & Field::flagSystem || $item->flags & Field::flagPermanent) {
         $item->flags = $item->flags | Field::flagSystemOverride;
         if ($item->flags & Field::flagSystem) {
             $item->flags = $item->flags & ~Field::flagSystem;
         }
         if ($item->flags & Field::flagPermanent) {
             $item->flags = $item->flags & ~Field::flagPermanent;
         }
         $item->flags = $item->flags & ~Field::flagSystemOverride;
     }
     // don't clone the 'global' flag
     if ($item->flags & Field::flagGlobal) {
         $item->flags = $item->flags & ~Field::flagGlobal;
     }
     return parent::___clone($item);
 }
 /**
  * Delete a template and unset it from this object. 
  *
  */
 public function ___delete(Saveable $item)
 {
     $cnt = $item->getNumPages();
     if ($cnt > 0) {
         throw new WireException("Can't delete template '{$item->name}' because it is used by {$cnt} pages.");
     }
     return parent::___delete($item);
 }
 /**
  * Create and return a cloned copy of this template
  *
  * Note that this also clones the Fieldgroup if the template being cloned has it's own named fieldgroup.
  *
  * @param Template|Saveable $item Item to clone
  * @param string $name
  * @return bool|Saveable|Template $item Returns the new clone on success, or false on failure
  *
  */
 public function ___clone(Saveable $item, $name = '')
 {
     $original = $item;
     $item = clone $item;
     if ($item->flags & Template::flagSystem) {
         // we want to avoid creating clones that have system flags
         $item->flags = $item->flags | Template::flagSystemOverride;
         $item->flags = $item->flags & ~Template::flagSystem;
         $item->flags = $item->flags & ~Template::flagSystemOverride;
     }
     $item->id = 0;
     // note this must be after removing system flags
     $fieldgroup = $item->fieldgroup;
     if ($fieldgroup->name == $item->name) {
         // if the fieldgroup and the item have the same name, we'll also clone the fieldgroup
         $fieldgroup = $this->wire('fieldgroups')->clone($fieldgroup, $name);
         $item->fieldgroup = $fieldgroup;
     }
     $item = parent::___clone($item, $name);
     if ($item && $item->id && !$item->altFilename) {
         // now that we have a clone, lets also clone the template file, if it exists
         $path = $this->wire('config')->paths->templates;
         $file = $path . $item->name . '.' . $this->wire('config')->templateExtension;
         if ($original->filenameExists() && is_writable($path) && !file_exists($file)) {
             if (copy($original->filename, $file)) {
                 $item->filename = $file;
             }
         }
     }
     return $item;
 }
 /**
  * Per WireSaveableItems interface, delete a Field from the database
  *
  */
 public function ___delete(Saveable $item)
 {
     if (!$this->fieldsArray->isValidItem($item)) {
         throw new WireException("Fields::delete(item) only accepts items of type Field");
     }
     // if the field doesn't have an ID, so it's not one that came from the DB
     if (!$item->id) {
         throw new WireException("Unable to delete from '" . $item->getTable() . "' for field that doesn't exist in fields table");
     }
     // if it's in use by any fieldgroups, then we don't allow it to be deleted
     if ($item->numFieldgroups()) {
         throw new WireException("Unable to delete field '{$item->name}' because it is in use by " . $item->numFieldgroups() . " fieldgroups");
     }
     // delete entries in fieldgroups_fields table. Not really necessary since the above exception prevents this, but here in case that changes.
     $this->fuel('fieldgroups')->deleteField($item);
     // drop the field's table
     $item->type->deleteField($item);
     return parent::___delete($item);
 }
 /** 
  * Delete the provided item from the database
  *
  */
 public function ___delete(Saveable $item)
 {
     $this->fuel('db')->query("DELETE FROM " . $this->getLookupTable() . " WHERE " . $this->getTable() . "_id={$item->id}");
     return parent::___delete($item);
 }
 /**
  * Delete the Permission, per WireSaveableItems interface
  *
  * WireSaveableItems (parent) handles deletion of the permission, and this deletes references to the permission in the lookup table
  *
  */
 public function ___delete(Saveable $item)
 {
     $id = (int) $item->id;
     $this->getFuel('db')->query("DELETE FROM roles_permissions WHERE permissions_id='{$id}'");
     return parent::___delete($item);
 }