DBCRUD#

NAME#

Kernel::System::DBCRUD

new()#

Don’t use the constructor directly, use the ObjectManager instead:

my $DBCRUDObject = $Kernel::OM->Get('Kernel::System::DBCRUD');

DataAdd()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Add data to table.

my $Success = $DBCRUDObject->DataAdd(
    ID          => '...',
    # ...
    CreateTime  => '...', # optional
    ChangeTime  => '...', # optional
);

Returns:

my $Success = 1;

DataUpdate()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Update data attributes.

my $Success = $DBCRUDObject->DataUpdate(
    ID     => 1234,
    UserID => 1,
    # all other attributes are optional
);

Returns:

my $Success = 1; # 1|0

DataGet()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Get data attributes.

my %Data = $DBCRUDObject->DataGet(
    ID          => '...', # optional
    CreateTime  => '...', # optional
    ChangeTime  => '...', # optional
);

Returns:

my %Data = (
    ID          => '...',
    CreateTime  => '...',
    ChangeTime  => '...',
);

DataListGet()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Get list data with attributes.

my @Data = $DBCRUDObject->DataListGet(
    ID          => '...', # optional
    CreateTime  => '...', # optional
    ChangeTime  => '...', # optional
);

Returns:

my @Data = (
    {
        ID          => '...',
        CreateTime  => '...',
        ChangeTime  => '...',
    },
    # ...
);

DataSearch()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Search for value in defined attributes.

my %Data = $DBCRUDObject->DataSearch(
    Search      => 'test*test',
    ID          => '...', # optional
    CreateTime  => '...', # optional
    ChangeTime  => '...', # optional
);

Returns:

my %Data = (
    '1' => {
        ID          => '...',
        CreateTime  => '...',
        ChangeTime  => '...',
    },
    # ...
);

DataDelete()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Remove data from table.

my $Success = $DBCRUDObject->DataDelete(
    ID          => '...', # optional
    CreateTime  => '...', # optional
    ChangeTime  => '...', # optional
);

Returns:

my $Success = 1;

DataExport()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Exports data.

my $Export = $DBCRUDObject->DataExport(
    Format => 'yml',
    Cache  => 0,
    Filter => {
        Source => '...'
    }
);

Returns:

my $Export = 'STRING';

DataImport()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Imports data.

my $Success = $DBCRUDObject->DataImport(
    Content   => $ContentString,
    Format    => 'yml',                 # optional - default
    Overwrite => 1,                     # optional to overwrite existing data
    Data      => {                      # additional data if not all needed data exists
        ValidID => 1,
    }
);

Returns:

my $Success = 1;

DataCopy()#

To use this function you need a DB CRUD module like e.g. Kernel::System::UnitTest::DBCRUD.

Copies object.

my $ObjectID = $DBCRUDObject->DataCopy(
    ID     => 123,
    UserID => 123,
);

Returns:

my $ObjectID = 141;

DataNameExists()#

Checks if the given name already exists in the table ‘name’.

my $Success = $DBCRUDObject->DataNameExists(
    Name   => 'name',
    UserID => 123,
);

Returns:

my $Success = 1;

IsUUIDDatabaseTableColumnPresent()#

Checks if the column for the UUID.

my $UUIDColumnPresent = $DBCRUDObject->IsUUIDDatabaseTableColumnPresent();

Returns true value if column for UUID is present.

CreateUUIDDatabaseTableColumn()#

Creates the UUID database table column.

my $UUIDColumnCreated = $DBCRUDObject->CreateUUIDDatabaseTableColumn();

Returns true value if column has been created successfully.

CreateMissingUUIDDatabaseTableColumns()#

Creates missing UUID database table column in backend's database table
and it's history database table, if one is configured.

my $Success = $DBCRUDObject->CreateMissingUUIDDatabaseTableColumns();

Returns true value on success (also if columns already existed).
Returns false value if something went wrong.

MigrateUUIDDatabaseTableColumns()#

Renames the UUID column from z4o_database_backend_uuid (used up until Znuny 6.0) or
database_backend_uuid (used in Znuny 6.1 and 6.2) to dbcrud_uuid (Znuny 6.3 and up).
Also includes table from history backend, if present.

my $Success = $DBCRUDObject->MigrateUUIDDatabaseTableColumns();

Returns true value on success.

_WhereTimeStamp()#

Additional WHERE to handle TimeStamp clauses.

my %Result = $Self->_WhereTimeStamp(
    Param  => {
        'ChangeTimeNewerDate'  => '2016-04-15 10:45:00',
        'ChangeTimeNewerUnit'  => 'Minutes',
        'ChangeTimeNewerValue' => 2
    }
    Column => {
        'TimeStampAdd' => 1,
        'Column'       => 'create_time',
        'Name'         => 'CreateTime',
        'TimeStamp'    => 1
    }
);

Returns:

my %Result = {
    'Where' => [
        'change_time >= ?'
    ],
    'Bind' => [
        \'2016-04-15 10:47:00'
    ],
    'Cache' => [
        'ChangeTimeNewerDate::2016-04-15 10:47:00'
    ]
};