Store any data in the panel database
Sometimes, when writing plugins, there is a need to store additional parameters for built-in objects. COREmanager (Class mgr db::Cache) allows you to add additional fields to database tables without making changes to the application code. At the same time, the added fields will be processed by standard algorithms: the presence of this field in the table and its type will be tracked (if necessary, the field will be added or its type will be changed), the values of such fields can be changed through the editing form or displayed in the list of records (it will be enough just to add the corresponding field to the metadata).
In order to add an additional field to a table, it is necessary to create the directory /usr/local/mgr5/etc/sql/{product_name}.{table_name}.addon or /usr/local/mgr5/etc/sql/{table_name}.addon
Each file in either of these directories describes a different field in the table. The field name is the same as the file name. By default, a field of type string with the maximum possible length (VARCHAR(255)) will be created, but you can set another data type, as well as define the default value and access parameters (Struct mgr_db::TableDesc::Field). Example file:
type=string
size=40
access_read= registered
access_write=admin+
default=0.0.0.0
type defines the type of the field. Possible values are the names of classes - heirs of class mgr db::Field. For example: name string, creates a field of type class mgr_db::StringField. int - class mgr_db::IntField
size the size of the field (for class mgr_db::StringField). Default: 255
access_read restricts access to read the field value by user access level (see Namespace mgr access ). By default, the field is available to all users.
access_write write access (similar to access_read)
access sets read and write access and overrides the settings set via (access_read and access_write).
default sets the default value. To set the value to NULL, you must specify the parameter as follows:
default null
After that, clear the cache and restart the panel:
rm -rf /usr/local/mgr5/var/.db.cache*
killall core