PHPackages                             omatech/editora-dbinterface - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. omatech/editora-dbinterface

ActiveLibrary[Database &amp; ORM](/categories/database)

omatech/editora-dbinterface
===========================

Extract or Load information from Editora in powerful and misterious ways using closures with Eloquant like syntax

v1.8(4mo ago)14.1k11PHPCI failing

Since Jun 7Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/omatech/editora-dbinterface)[ Packagist](https://packagist.org/packages/omatech/editora-dbinterface)[ RSS](/packages/omatech-editora-dbinterface/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (50)Used By (1)

Editora-Extractor
=================

[](#editora-extractor)

Extract info from omatech Editora using closure Eloquent like functions

First make a new instance
-------------------------

[](#first-make-a-new-instance)

```
// Create a new database connection
$connectionParams = array(
    'dbname' => 'xxx',
    'user' => 'xxx',
    'password' => 'xxx',
    'host' => 'xxx',
    'driver' => 'pdo_mysql',
		'charset' => 'utf8mb4'
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, new \Doctrine\DBAL\Configuration());

// Set-up the global params of the extraction (language,...) (See the "Global Params" section for more info)
$params = [
	'lang' => 'es'
	, 'debug' => false
	, 'metadata' => true
];

// Instantiate the extractor using the connection and params
$e=new Extractor($conn, $params);

```

Extract information using the extractor
---------------------------------------

[](#extract-information-using-the-extractor)

### findInstanceByIdAllElements($inst\_id, $params = null, $num = null, $level = 1, callable $callback = null)

[](#findinstancebyidallelementsinst_id-params--null-num--null-level--1-callable-callback--null)

- inst\_id \* (id of the instance to be extracted)
- params (particular params for this extraction, see "Extraction Params" and "Instance Params" for more info)
- level number of relations to extract
- callback (closure function)

### findInstanceById($inst\_id, $params, callable $callback = null);

[](#findinstancebyidinst_id-params-callable-callback--null)

- inst\_id \* (id of the instance to be extracted)
- params (particular params for this extraction, see "Extraction Params" and "Instance Params" for more info)
- callback (closure function)

### findInstancesInClass($class, $num=null, $params=null, callable $callback = null)

[](#findinstancesinclassclass-numnull-paramsnull-callable-callback--null)

- class \* (id or tag of the class)
- num (number of instances to extract, if not set get all instances of the class. Use an int to not use pagination or syntax "10/2" to give the records 11 to 20) (see paginator section for details)
- params (particular params for this extraction, see "Extraction Params" and "Instance Params" for more info)
- callback (closure function)

#### Extraction params

[](#extraction-params)

- order = order class instances by order criteria, update\_date|publishing\_begins|inst\_id|key\_fields|order\_date|order\_string default publishing\_begins
- order\_direction = direction of the order by clause, desc|asc defaults to asc

### findInstancesInList($inst\_ids, $num=null, $class=null, $params = null, callable $callback = null)

[](#findinstancesinlistinst_ids-numnull-classnull-params--null-callable-callback--null)

- inst\_ids \* (comma separated ids of instances to extract)
- num (number of instances to extract, if not set get all instances of the class). Use an int to not use pagination or syntax "10/2" to give the records 11 to 20) (see paginator section for details)
- class (filter one particular class by tag or id)
- params (particular params for this extraction, see "Extraction Params" and "Instance Params" for more info)
- callback (closure function)

Note: The order of the extraction is forced by the order of the IDs in the list

### findInstancesBySearch($query, $num=null, $class=null, $params = null, callable $callback = null)

[](#findinstancesbysearchquery-numnull-classnull-params--null-callable-callback--null)

- query \* (the search term)
- num (number of instances to extract, if not set get all instances of the class). Use an int to not use pagination or syntax "10/2" to give the records 11 to 20) (see paginator section for details)
- class (filter one particular class by tag or id)
- params (particular params for this extraction, see "Extraction Params" and "Instance Params" for more info)
- callback (closure function)

Note: The order of the extraction is forced by the relevance of the search term (query)

### findRelatedInstances($inst\_id, $relation, $num=null, $params = null, callable $callback = null)

[](#findrelatedinstancesinst_id-relation-numnull-params--null-callable-callback--null)

- inst\_id \* (parent or child instance to start search)
- relation \* (tag or id of the relation)
- num (number of instances to extract, if not set get all instances of the class). Use an int to not use pagination or syntax "10/2" to give the records 11 to 20) (see paginator section for details)
- params (particular params for this extraction, see "Extraction Params" and "Instance Params" for more info)
- callback (closure function)

#### Extraction params

[](#extraction-params-1)

- direction (child|parent) Allows to force the direction of the relation for cases where the relation is parent and child of a class, if not set tries to find the direction automatically
- alias (string) (default tag of the relation) alias of the relation to extract

### findChildrenInstances($inst\_id, $relation, $num=null, $params = null, callable $callback = null)

[](#findchildreninstancesinst_id-relation-numnull-params--null-callable-callback--null)

(same as findRelatedInstances but forcing child direction)

### findParentInstances($inst\_id, $relation, $num=null, $params = null, callable $callback = null)

[](#findparentinstancesinst_id-relation-numnull-params--null-callable-callback--null)

(same as findRelatedInstances but forcing parent direction)

Instance Params
---------------

[](#instance-params)

The instance params affect the behaviour of the extraction of the instance itself

- filter (string) (default all)
    - all - extracts all the attributes of the instance (even if it's value is null)
    - detail - extracts only attributes with the class\_attribute.detail='Y'
    - resume - extracts only attributes with the class\_attribute.detail='N'
        - only-X - are values only of the attribute\_type=X (for example S for string type only)
        - except-Y are values excluding attribute\_type=Y (for example K to avoid K attributes that are usually long)
    - fields:fieldname1|fieldname2

Additional calls
----------------

[](#additional-calls)

### findClass($class)

[](#findclassclass)

- class \* (filter one particular class by tag or id)

### findRelation($relation)

[](#findrelationrelation)

- relation \* (tag or id of the relation in case of collision you can use the calls below)

### findParentRelation($relation, $inst\_id)

[](#findparentrelationrelation-inst_id)

- relation \* (tag or id of the relation)
- inst\_id \* (instance to start looking at parent relations)

### findChildRelation($relation, $inst\_id)

[](#findchildrelationrelation-inst_id)

- relation \* (tag or id of the relation)
- inst\_id \* (instance to start looking at children relations)

### clearExtractionCache($extraction\_cache\_key);

[](#clearextractioncacheextraction_cache_key)

Global Params
-------------

[](#global-params)

The format of the params is a key value par in an array, for example:

$params = \[ 'lang' =&gt; 'es' , 'debug' =&gt; false , 'metadata' =&gt; true . 'show\_inmediate\_debug' =&gt; true \];

The global params can be:

- lang (2 characters ISO language code or ALL) (default ALL) ('ALL' for only non-language dependent attributes, 'es' for spanish and non-language dependent attributes, 'en' for english, etc.
- debug (boolean) (default false) Enable debugging, you can check the debug messages afterwards using $e-&gt;debug\_messages
- show\_inmediate\_debug (boolean) (default false) If debugging is enabled echo directly the debug messages in addition to store them in debug\_messages
- metadata (boolean) (default false) Enable metadata output, info like status, publishing\_begins, publishing\_ends etc
- default\_limit (int) (default 10000) - Set the default limit when no limit is set in the call
- cache\_expiration (int) (default 3600 (1 hour)) seconds to expire cached instances
- avoid\_cache (boolean) (default false) Prevents the use of the cache system
- preview (boolean) (default false) Sets the extractor in preview mode
- preview\_date (string mysql date) (default "NOW()") Sets the preview\_date of the extractor, only make sense if preview=true, for example preview an extraction in '2020-01-01'
- extract\_values (boolean) (default true) Extracts values of the instance (even null)
- sql\_select\_instances (mysql select string) (default: select i.\*, c.name class\_name, c.tag class\_tag, c.id class\_id, i.key\_fields nom\_intern, i.update\_date, ifnull(unix\_timestamp(i.update\_date),0) update\_timestamp)
- timings (boolean) default false show start and end and total milliseconds for each extraction, only make sense if metadata is true
- extraction\_cache\_key key of the extraction, for example 'menu' or 'footer' or 'countries'
- extraction\_cache\_expiration optional, sets the time of expiration for the extraction cache, if not set cache\_expiration is used
- default\_language\_to\_remove\_from\_url, sets a language that is removed from the link of each instance, for example if default\_language\_to\_remove\_from\_url='es' then a usual link generated from extractor '/es/nice-url-in-spanish-instance' is replaced by '/nice-url-in-spanish-instance' only works if is set to a language two character code, for example 'es' or 'en'

Combine extractions with the callable parameter
-----------------------------------------------

[](#combine-extractions-with-the-callable-parameter)

```
    $result = $extractor->findInstanceById($id, $params, function ($i) use ($extractor){
        $blocks = $extractor->findChildrenInstances($i, "blocks", null, null, function ($i) use ($extractor){
            $boxes = $extractor->findChildrenInstances($i, "boxes", null, null, null);
            return array_merge($boxes);
        });
        return array_merge($blocks);
    });

```

How Cache works?
----------------

[](#how-cache-works)

By default all the instances that get extracted from the CMS are cached in memcache, to avoid that behaviour you must set the avoid\_cache param.

The instance itself is saved in memcache with the following key: DATABASE\_NAME:dbinterface:LANGUAGE:INST\_ID:FILTER

The instance cache has an expiration time of 3600 seconds by default but can be changed using the cache\_expiration param.

If the instance cached is modified in the CMS the cache is automatically expired, the column update\_date is the reference to expire the cache of the instance

If you need to use a cache at an extraction level you can use the built in extraction caching system.

The extraction gets cached until the extraction\_cache\_expiration seconds are reached, so you must be responsible to clear the cache if you need to or to setup a time brief enough to not get stale content from the CMS

The extraction is saved in memcache with the following key DATABASE\_NAME::extractor\_cache:EXTRACTION\_CACHE\_KEY:LANGUAGE

Use the function $e-&gt;clearExtractionCache(extraction\_cache\_key) to clear a particular key (the same that you use extraction\_cache\_key

Pagination
----------

[](#pagination)

In the main calls of the extractor you can use pagination syntax in the $num parameter, for example:

- use 10/3 to extract page 3 of instances with 10 elements per page
- use 50/1 to extract first page with 50 elements per page

### How to get more info about the pagination once used?

[](#how-to-get-more-info-about-the-pagination-once-used)

Use the call getPaginator to get all the relevant information about the paginated results.

### getPaginator ($prefix='', $postfix='')

[](#getpaginator-prefix-postfix)

- prefix is the prefix of the url to generate in the results of paginator
- postfix is the postfix of the url to generate in the results of paginator

for example:

```
$paginator=$extractor->getPaginator('/ca/news/', '?utm_source=xxx');

```

This will generate the following output (assuming that the last pagination option was 10/3 third page with 10 elements and that the total records are 51)

```
$paginator=[
'lastPage'=>false
,'firstPage'=>false
,'hasMorePages'=>true
,'nextPage'=>4
,'previousPage'=>2
,'onFirstPage'=>false
,'currentPage'=>3
'elements'=>[
	1=>['url'=>'/ca/news/1?utm_source=xxx'
		, 'isFirst'=>true
		, 'isLast'=>false
		, 'isCurrent=>false
	]
	2=>['url'=>'/ca/news/2?utm_source=xxx'
		, 'isFirst'=>false
		, 'isLast'=>false
		, 'isCurrent=>false
	]
	3=>['url'=>'/ca/news/3?utm_source=xxx'
		, 'isFirst'=>false
		, 'isLast'=>false
		, 'isCurrent=>true
	]
	4=>['url'=>'/ca/news/4?utm_source=xxx'
		, 'isFirst'=>false
		, 'isLast'=>false
		, 'isCurrent=>false
	]
	5=>['url'=>'/ca/news/5?utm_source=xxx'
		, 'isFirst'=>false
		, 'isLast'=>false
		, 'isCurrent=>false
	]
	6=>['url'=>'/ca/news/6?utm_source=xxx'
		, 'isFirst'=>false
		, 'isLast'=>true
		, 'isCurrent=>false
	]
]
];

```

### Get last updated timestamp from a given extraction

[](#get-last-updated-timestamp-from-a-given-extraction)

$extractor-&gt;last\_updated\_timestamp; Returns the last updated unix timestamp of all the elements extracted

Test the Extractor
------------------

[](#test-the-extractor)

1. Create a database if not exists with utf8\_mb4 and collate utf8\_mb4\_general\_ci in this example assume editora\_test in localhost, we'll assume user root and without password
2. Go to Commands folder

cd Commands

3. Generate the editora structure (remember to change your database connection params)

php generate-editora.php --from=file --inputformat=array --inputfile=../data/sample\_editora\_array.php --to=db4 --dbtohost=localhost --dbtouser=root --dbtopass= --dbtoname=editora\_test

The command will output 2 users with random passwords, for example:

New user: omatech with password eJjZQU&amp;5 New user: test with password 6r4!QBPB

4. Populate the editora with fake content

php fake-content.php --to=db4 --dbhost=localhost --dbuser=root --dbpass= --dbname=editora\_test --num\_instances=6

The command will output something like this:

Content created: 126 instances 959 attributes and 126 relation instances created with batch\_id=1533716151

Note: If you want to remove this fake data in the future you can use:

php remove-content.php --to=db4 --dbhost=localhost --dbuser=root --dbpass= --dbname=editora\_test --batch\_id=1533716151

5. Go to the root folder of the project

cd ..

6. Run the tests to see that everything is fine!

In windows

phpunit ./tests/Omatech/Editora/Extractor/ExtractorTest

o in Linux

vendor/bin/phpunit ./tests/Omatech/Editora/Extractor/ExtractorTest

Editora-Loader
==============

[](#editora-loader)

Compare methods
---------------

[](#compare-methods)

### relationInstanceExist($rel\_id, $parent\_inst\_id, $child\_inst\_id)

[](#relationinstanceexistrel_id-parent_inst_id-child_inst_id)

### existsInstanceWithExternalID($class\_id, $external\_id)

[](#existsinstancewithexternalidclass_id-external_id)

### ExistingInstanceIsDifferent($inst\_id, $nom\_intern, $values, $status = 'O', &amp;$difference, &amp;$attr\_difference)

[](#existinginstanceisdifferentinst_id-nom_intern-values-status--o-difference-attr_difference)

```
	// -1 instance not exist
	// -2 status is different
	// -3 nom_intern is different
	// -4 some value is different
	// -5 some value not exists in current instance
	// 0 same!

```

Insert/Update methods
---------------------

[](#insertupdate-methods)

### insertRelationInstance($rel\_id, $parent\_inst\_id, $child\_inst\_id, $external\_id = null, $batch\_id = null)

[](#insertrelationinstancerel_id-parent_inst_id-child_inst_id-external_id--null-batch_id--null)

### updateInstance($inst\_id, $nom\_intern, $values, $status = 'O', $publishing\_begins = null, $publishing\_ends = null)

[](#updateinstanceinst_id-nom_intern-values-status--o-publishing_begins--null-publishing_ends--null)

### insertInstanceWithExternalID($class\_id, $nom\_intern, $external\_id, $batch\_id, $values, $status = 'O', $publishing\_begins = null, $publishing\_ends = null, $creation\_date = 'now()', $update\_date = 'now()') {

[](#insertinstancewithexternalidclass_id-nom_intern-external_id-batch_id-values-status--o-publishing_begins--null-publishing_ends--null-creation_date--now-update_date--now-)

### insertInstance($class\_id, $nom\_intern, $values, $status = 'O', $publishing\_begins = null, $publishing\_ends = null)

[](#insertinstanceclass_id-nom_intern-values-status--o-publishing_begins--null-publishing_ends--null)

### insertInstanceForcingID($inst\_id, $class\_id, $nom\_intern, $values, $status = 'O', $publishing\_begins = null, $publishing\_ends = null)

[](#insertinstanceforcingidinst_id-class_id-nom_intern-values-status--o-publishing_begins--null-publishing_ends--null)

### updateUrlNice($nice\_url, $inst\_id, $language)

[](#updateurlnicenice_url-inst_id-language)

### insertUrlNice($nice\_url, $inst\_id, $language)

[](#inserturlnicenice_url-inst_id-language)

Delete methods
--------------

[](#delete-methods)

### deleteInstance ($inst\_id)

[](#deleteinstance-inst_id)

- inst\_id \* (instance to delete)

### deleteInstancesWithExternalID ($external\_id, $class\_id)

[](#deleteinstanceswithexternalid-external_id-class_id)

### deleteRelationInstancesWithExternalID($external\_id, $rel\_id)

[](#deleterelationinstanceswithexternalidexternal_id-rel_id)

### delete\_instance($inst\_id)

[](#delete_instanceinst_id)

### deleteInstancesInBatch($batch\_id)

[](#deleteinstancesinbatchbatch_id)

### deleteRelationInstancesInBatch($batch\_id)

[](#deleterelationinstancesinbatchbatch_id)

### deleteRelationInstance($id)

[](#deleterelationinstanceid)

Commands
========

[](#commands)

Editora Structure
-----------------

[](#editora-structure)

### generate-editora.php

[](#generate-editoraphp)

Generate editora structure from an array or json file

### reverse-engineer-editora.php

[](#reverse-engineer-editoraphp)

Takes out the editora structure and generates a compatible generator file

### compare-editoras.php

[](#compare-editorasphp)

Compare two editora structures in two local databases, get a report of the differences between them

### modernize.php

[](#modernizephp)

Modernize editora DB to include latest changes in DB structure

### regenerate-passwords.php

[](#regenerate-passwordsphp)

Reset all the passwords in the database using a string with uppercase, lowercase, symbols and numbers

Content manipulation
--------------------

[](#content-manipulation)

### fake-content.php

[](#fake-contentphp)

Populate the editora CMS with fake content

### export-content.php

[](#export-contentphp)

Export all editora contents to a file or input (json or serialized array)

### import-content.php

[](#import-contentphp)

Import all editora contents from a file or input (json or serialized\_array)

### remove-content.php

[](#remove-contentphp)

Remove all content with a given batch\_id or all content except Global and Home if delete\_previous\_data flag is present

Translation
-----------

[](#translation)

export-translation.php
----------------------

[](#export-translationphp)

Export strings in one language from editora database to excel file or output

import-translation.php
----------------------

[](#import-translationphp)

Import strings from an excel, json file or input to editora database

field parents and full\_niceurl
-------------------------------

[](#field-parents-and-full_niceurl)

Now the omp\_niceurl table will have the parents field, which will contain the IDs of its parents separated by commas, and the full\_niceurl field will have the parents + the niceurl to distinguish the niceurl in case there are two duplicates. All of this will be filled in automatically if the instances have a relationship called 'Childs'.

Experimental
------------

[](#experimental)

### data-transfer.php

[](#data-transferphp)

Use data\_transfer.php to extract editora4 information and get it into editora5 format

### translate.php

[](#translatephp)

Use Google translate API to automatically translate content

### migrator.php

[](#migratorphp)

Use migrator.php to extract editora4 information and get it into editora5 format, transfer directly to a db5 database or generate 3 different file formats (full, minimal, generator)

### export-allinstances-mongo

[](#export-allinstances-mongo)

Export all instances to the output or a file in json format.

Attributes types:
=================

[](#attributes-types)

- A: Text Area WYSIWYG
- B: Short string used to order instances
- C: Text Area Code
- D: Date
- E: Date used to order instances
- F: File
- G: Flash File
- H: Grid Image
- I: Image
- K: Text Area CKEDITOR
- L: Lookup
- M: Geolocation (Google Maps)
- N: Number
- O: Color Selector
- R: Relation
- S: Short string
- T: Text Area HTML
- U: URL
- W: Type APP
- X: XML
- Y: Video (Youtube or Vimeo)
- Z: url nice

Class diagram
=============

[](#class-diagram)

[![](Documentation/editora.png)](Documentation/editora.png)

Authors
=======

[](#authors)

- Agusti Pons
- Christian Bohollo
- Javier Mogollon
- Hector Arnau
- Alvaro Aguilar
- Cesc Delgado

License
=======

[](#license)

This project is licensed under the MIT License

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance77

Regular maintenance activity

Popularity22

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~48 days

Recently: every ~110 days

Total

44

Last Release

126d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a6b2440a7864015d71501a9cd77d28bed549c283afdd8d1af95f54b650dc833?d=identicon)[aponscat](/maintainers/aponscat)

---

Top Contributors

[![hectorarnau](https://avatars.githubusercontent.com/u/10995071?v=4)](https://github.com/hectorarnau "hectorarnau (37 commits)")[![adriaroca](https://avatars.githubusercontent.com/u/3205030?v=4)](https://github.com/adriaroca "adriaroca (31 commits)")[![aponscat](https://avatars.githubusercontent.com/u/20087234?v=4)](https://github.com/aponscat "aponscat (22 commits)")[![omaroca](https://avatars.githubusercontent.com/u/10994187?v=4)](https://github.com/omaroca "omaroca (19 commits)")[![AlvaroOmatech](https://avatars.githubusercontent.com/u/14976137?v=4)](https://github.com/AlvaroOmatech "AlvaroOmatech (11 commits)")[![hondilla](https://avatars.githubusercontent.com/u/7813599?v=4)](https://github.com/hondilla "hondilla (9 commits)")[![eudaldca](https://avatars.githubusercontent.com/u/8332105?v=4)](https://github.com/eudaldca "eudaldca (5 commits)")[![omacesc](https://avatars.githubusercontent.com/u/1949963?v=4)](https://github.com/omacesc "omacesc (4 commits)")[![jabello187](https://avatars.githubusercontent.com/u/125561460?v=4)](https://github.com/jabello187 "jabello187 (2 commits)")[![rubenmaralc](https://avatars.githubusercontent.com/u/119672520?v=4)](https://github.com/rubenmaralc "rubenmaralc (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/omatech-editora-dbinterface/health.svg)

```
[![Health](https://phpackages.com/badges/omatech-editora-dbinterface/health.svg)](https://phpackages.com/packages/omatech-editora-dbinterface)
```

###  Alternatives

[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[forkcms/forkcms

Fork is an open source CMS that will rock your world.

1.2k44.5k](/packages/forkcms-forkcms)[pixelfederation/doctrine-resettable-em-bundle

Symfony bundle for decorating default entity managers using a resettable decorator.

20113.5k](/packages/pixelfederation-doctrine-resettable-em-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
