Yoast\WP\Lib
ORM::save() public Yoast 1.0
Saves any fields which have been modified on this object to the database.
{} Это метод класса: ORM{}
Хуков нет.
Возвращает
true/false. True on success.
Использование
$ORM = new ORM(); $ORM->save();
Код ORM::save() ORM::save Yoast 15.9.1
public function save() {
global $wpdb;
// Remove any expression fields as they are already baked into the query.
$values = \array_values( \array_diff_key( $this->dirty_fields, $this->expr_fields ) );
if ( ! $this->is_new ) {
// UPDATE.
// If there are no dirty values, do nothing.
if ( empty( $values ) && empty( $this->expr_fields ) ) {
return true;
}
$query = \join( ' ', [ $this->build_update(), $this->add_id_column_conditions() ] );
$id = $this->id( true );
if ( \is_array( $id ) ) {
$values = \array_merge( $values, \array_values( $id ) );
}
else {
$values[] = $id;
}
}
else {
// INSERT.
$query = $this->build_insert();
}
$success = self::execute( $query, $values );
// If we've just inserted a new record, set the ID of this object.
if ( $this->is_new ) {
$this->is_new = false;
if ( $this->count_null_id_columns() !== 0 ) {
$column = $this->get_id_column_name();
// If the primary key is compound, assign the last inserted id to the first column.
if ( \is_array( $column ) ) {
$column = \reset( $column );
}
// Explicitly cast to int to make dealing with Id's simpler.
$this->data[ $column ] = (int) $wpdb->insert_id;
}
}
$this->dirty_fields = [];
$this->expr_fields = [];
return $success;
}