protected function deleteRows($conditions, &$files_to_delete = array()) { if (!$conditions) { return true; } $rows = $this->getAllRows($conditions); $files_to_delete = $this->getFilesToDelete($rows, $files_to_delete); /** * Creates an array with all the the primary_key => value pairs of all the rows that have to be deleted. */ $row_conditions = array(); foreach ($rows as $row) { $values = array(); foreach ($this->primary as $primary) { $values[$primary] = $row[$primary]; } $row_conditions[] = $values; } $children = $this->schema->getChildren($this->name); foreach ($children as $child) { if (!isset($child['key'][2]) || is_null($child['key'][2])) { } elseif ($child['key'][2] == self::ON_DELETE_RESTRICT) { $reader = new TableReader($child['table']->getName()); foreach ($row_conditions as $row_condition) { foreach ($row_condition as $column => $value) { if ($column == $child['key'][1]) { $reader->where($column, $value); } } } if ($reader->count()) { return false; } } elseif ($child['key'][2] == self::ON_DELETE_CASCADE) { foreach ($row_conditions as $row_condition) { $child_conditions = array(); foreach ($row_condition as $column => $value) { if ($column == $child['key'][1]) { $child_conditions[$column] = $value; } } if (!$child['table']->deleteRows($child_conditions, $files_to_delete)) { return false; } } } elseif ($child['key'][2] == self::ON_DELETE_SET_NULL) { //Not implemented yet } } foreach ($this->getKeys() as $column => $key) { if ($key[2] == AdminTable::ON_DELETE_CASCADE_REVERSED) { $table = $this->schema->getTable($key[0]); foreach ($rows as $row) { if (!$table->deleteRows(array($key[1] => $row[$key[1]]), $files_to_delete)) { return false; } } } } $ds = new TableWriter($this->name); foreach ($conditions as $column => $value) { $ds->where($column, $value); } return $ds->delete(); }
private static function urlCountMatches($url_title, $table, $url_field, $extra) { $query = new TableReader($table); $query->where($url_field, $url_title, 'LIKE'); if ($extra) { $query->where($extra[0], $extra[1]); } return $query->count(); }