public function testRemove()
 {
     $table = 'table';
     $parentId = 'parent';
     $rowId = 'row';
     $data = new \stdClass();
     $this->object->setRow($table, $parentId, $rowId, $data);
     $this->object->remove($table, $parentId, $rowId, $data);
     $this->assertFalse($this->object->get($table, $parentId, $rowId));
 }
Esempio n. 2
0
    /**
     * Update one or more fields of table row
     *
     * @param string $table
     * @param string $idField
     * @param string|integer $rowId
     * @param string|array $field
     * @param mixed|null $value
     * @param string $parentField
     * @param string|integer $parentId
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function updateTableRow($table, $idField, $rowId, $field, $value = null, $parentField = null, $parentId = 0)
    {
        $table = $this->getTable($table);
        if (is_array($field)) {
            $data = $field;
        } else {
            $data = [$field => $value];
        }

        $connection = $this->getConnection();
        $where = [$connection->quoteIdentifier($idField) . '=?' => $rowId];
        $connection->update($table, $data, $where);

        if (is_array($field)) {
            $oldRow = $this->setupCache->has($table, $parentId, $rowId) ?
                $this->setupCache->get($table, $parentId, $rowId) :
                [];
            $newRowData = array_merge($oldRow, $field);
            $this->setupCache->setRow($table, $parentId, $rowId, $newRowData);
        } else {
            $this->setupCache->setField($table, $parentId, $rowId, $field, $value);
        }

        return $this;
    }