Esempio n. 1
0
 /**
  * Delete this data object.
  * $this->onBeforeDelete() gets called.
  * Note that in Versioned objects, both Stage and Live will be deleted.
  */
 public function delete()
 {
     $this->brokenOnDelete = true;
     $this->onBeforeDelete();
     if ($this->brokenOnDelete) {
         user_error("{$this->class} has a broken onBeforeDelete() function.  Make sure that you call parent::onBeforeDelete().", E_USER_ERROR);
     }
     foreach ($this->getClassAncestry() as $ancestor) {
         if (ClassInfo::hastable($ancestor)) {
             $sql = new SQLQuery();
             $sql->delete = true;
             $sql->from[$ancestor] = "`{$ancestor}`";
             $sql->where[] = "ID = {$this->ID}";
             $this->extend('augmentSQL', $sql);
             $sql->execute();
         }
     }
     $this->OldID = $this->ID;
     $this->ID = 0;
     DataObjectLog::deletedObject($this);
 }
Esempio n. 2
0
 protected function buildSelected($fields, &$ret, $includeAllFields = true)
 {
     if ($includeAllFields) {
         $ret1 = array();
         foreach (ClassInfo::subclassesFor($this->baseClass) as $subClass) {
             if (ClassInfo::hastable($subClass)) {
                 if ($columns = $this->getColumnsInTable($subClass)) {
                     foreach ($columns as $column) {
                         if (!in_array($column, $ret1)) {
                             $ret[] = "`{$subClass}`.`{$column}`";
                             $ret1[] = $column;
                         }
                     }
                 }
             }
         }
         if ($this->joinedTables) {
             foreach ($this->joinedTables as $table) {
                 $columns = $this->getColumnsInTable($table);
                 if ($columns) {
                     foreach ($columns as $column) {
                         if (!in_array($column, $ret1)) {
                             $ret[] = "`{$table}`.`{$column}`";
                             $ret1[] = $column;
                         }
                     }
                 }
             }
         }
     } else {
         foreach ($fields as $field) {
             if (is_array($field)) {
                 $this->buildSelected($field, $ret);
             } else {
                 if ($count = preg_match('/^(.+)->(.+)$/', $field, $matches)) {
                     $field = $matches[1];
                 }
                 if (!preg_match('/^(.+)\\.(.+)$/', $field, $matches)) {
                     if ($this->is_inTables($field)) {
                         $ret[] = $field;
                     }
                 } else {
                     $ret[] = $field;
                 }
             }
         }
     }
     foreach ($this->customSelect as $filter) {
         $ret[] = $filter;
     }
 }