2017-07-21 16:56:44 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once 'classes/model/om/BasePluginsRegistry.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'PLUGINS_REGISTRY' table.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
|
|
|
|
* application requirements. This class will only be generated as
|
|
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
|
*
|
|
|
|
|
* @package classes.model
|
|
|
|
|
*/
|
|
|
|
|
class PluginsRegistry extends BasePluginsRegistry
|
|
|
|
|
{
|
|
|
|
|
/**
|
2017-08-01 12:16:06 -04:00
|
|
|
* Load all Plugins
|
|
|
|
|
* @param string $keyType
|
2017-07-21 16:56:44 -04:00
|
|
|
* @return array
|
2017-08-01 12:16:06 -04:00
|
|
|
* @throws \Exception
|
2017-07-21 16:56:44 -04:00
|
|
|
*/
|
2017-08-01 12:16:06 -04:00
|
|
|
public static function loadPlugins($keyType = BasePeer::TYPE_FIELDNAME)
|
2017-07-21 16:56:44 -04:00
|
|
|
{
|
2017-08-01 12:16:06 -04:00
|
|
|
$criteria = new Criteria();
|
|
|
|
|
$dataSet = PluginsRegistryPeer::doSelect($criteria);
|
|
|
|
|
$plugins = [];
|
|
|
|
|
/** @var PluginsRegistry $row */
|
|
|
|
|
foreach ($dataSet as $row) {
|
|
|
|
|
$plugins[] = $row->toArray($keyType);
|
2017-07-21 16:56:44 -04:00
|
|
|
}
|
2017-08-01 12:16:06 -04:00
|
|
|
return $plugins;
|
2017-07-21 16:56:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-01 12:16:06 -04:00
|
|
|
* Get all Plugins Enabled
|
|
|
|
|
* @param string $keyType
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getPluginsEnabled($keyType = BasePeer::TYPE_FIELDNAME)
|
|
|
|
|
{
|
|
|
|
|
$criteria = new Criteria();
|
|
|
|
|
$criteria->add(PluginsRegistryPeer::PLUGIN_ENABLE, true);
|
|
|
|
|
$dataSet = PluginsRegistryPeer::doSelect($criteria);
|
|
|
|
|
$plugins = [];
|
|
|
|
|
/** @var PluginsRegistry $row */
|
|
|
|
|
foreach ($dataSet as $row) {
|
|
|
|
|
$plugins[] = $row->toArray($keyType);
|
|
|
|
|
}
|
|
|
|
|
return $plugins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load plugin with Uid
|
|
|
|
|
* @param string $prUid
|
2017-07-21 16:56:44 -04:00
|
|
|
* @return array
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2017-07-26 16:15:32 -04:00
|
|
|
public static function load($prUid)
|
2017-07-21 16:56:44 -04:00
|
|
|
{
|
2017-07-26 16:15:32 -04:00
|
|
|
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($prUid);
|
2017-07-21 16:56:44 -04:00
|
|
|
if ($oPluginsRegistry) {
|
|
|
|
|
/** @var array $aFields */
|
|
|
|
|
$aFields = $oPluginsRegistry->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
return $aFields;
|
|
|
|
|
} else {
|
2017-08-04 09:32:25 -04:00
|
|
|
throw new Exception("Plugin does not exist!");
|
2017-07-21 16:56:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-01 12:16:06 -04:00
|
|
|
* Check if there is a plugin uid
|
2017-07-26 16:15:32 -04:00
|
|
|
* @param $prUid
|
2017-07-21 16:56:44 -04:00
|
|
|
* @return mixed|bool
|
|
|
|
|
*/
|
2017-07-26 16:15:32 -04:00
|
|
|
public static function exists($prUid)
|
2017-07-21 16:56:44 -04:00
|
|
|
{
|
2017-07-26 16:15:32 -04:00
|
|
|
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPk($prUid);
|
2017-07-21 16:56:44 -04:00
|
|
|
if ($oPluginsRegistry) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-01 12:16:06 -04:00
|
|
|
* Load or creates if the record does not exist
|
|
|
|
|
* Load and makes a union with the data sent
|
|
|
|
|
*
|
|
|
|
|
* @param string $prUid
|
2017-07-21 16:56:44 -04:00
|
|
|
* @param array $pluginData
|
2017-08-01 12:16:06 -04:00
|
|
|
* @return array
|
2017-07-21 16:56:44 -04:00
|
|
|
*/
|
2017-08-01 12:16:06 -04:00
|
|
|
public static function loadOrCreateIfNotExists($prUid, $pluginData = [])
|
2017-07-21 16:56:44 -04:00
|
|
|
{
|
2017-07-26 16:15:32 -04:00
|
|
|
if (!self::exists($prUid)) {
|
|
|
|
|
$pluginData['PR_UID'] = $prUid;
|
2017-07-21 16:56:44 -04:00
|
|
|
self::create($pluginData);
|
|
|
|
|
} else {
|
2017-07-26 16:15:32 -04:00
|
|
|
$fields = self::load($prUid);
|
2017-07-21 16:56:44 -04:00
|
|
|
$pluginData = array_merge($fields, $pluginData);
|
|
|
|
|
}
|
|
|
|
|
return $pluginData;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 09:32:25 -04:00
|
|
|
/**
|
|
|
|
|
* Creates a record in the PLUGINS_REGISTRY table
|
|
|
|
|
* @param array $aData
|
|
|
|
|
* @return bool
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2017-07-21 16:56:44 -04:00
|
|
|
public static function create($aData)
|
|
|
|
|
{
|
|
|
|
|
$oConnection = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME);
|
|
|
|
|
try {
|
|
|
|
|
$oPluginsRegistry = new PluginsRegistry();
|
|
|
|
|
$oPluginsRegistry->fromArray($aData, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
if ($oPluginsRegistry->validate()) {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$oPluginsRegistry->save();
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$sMessage = '';
|
|
|
|
|
$aValidationFailures = $oPluginsRegistry->getValidationFailures();
|
|
|
|
|
/** @var ValidationFailed $oValidationFailure */
|
|
|
|
|
foreach ($aValidationFailures as $oValidationFailure) {
|
|
|
|
|
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
|
|
|
|
}
|
|
|
|
|
throw (new Exception('The registry cannot be created!<br />' . $sMessage));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 09:32:25 -04:00
|
|
|
/**
|
|
|
|
|
* Modifies a record in the PLUGINS_REGISTRY table
|
|
|
|
|
* @param array $aData
|
|
|
|
|
* @return int
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2017-07-21 16:56:44 -04:00
|
|
|
public static function update($aData)
|
|
|
|
|
{
|
2017-07-24 16:29:18 -04:00
|
|
|
$oConnection = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME);
|
2017-07-21 16:56:44 -04:00
|
|
|
try {
|
|
|
|
|
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($aData['PR_UID']);
|
|
|
|
|
if ($oPluginsRegistry) {
|
|
|
|
|
$oPluginsRegistry->fromArray($aData, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
if ($oPluginsRegistry->validate()) {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$iResult = $oPluginsRegistry->save();
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return $iResult;
|
|
|
|
|
} else {
|
|
|
|
|
$sMessage = '';
|
|
|
|
|
$aValidationFailures = $oPluginsRegistry->getValidationFailures();
|
|
|
|
|
/** @var ValidationFailed $oValidationFailure */
|
|
|
|
|
foreach ($aValidationFailures as $oValidationFailure) {
|
|
|
|
|
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
|
|
|
|
}
|
|
|
|
|
throw (new Exception('The registry cannot be updated!<br />' . $sMessage));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception('This row doesn\'t exist!'));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-01 12:16:06 -04:00
|
|
|
|
2017-08-04 09:32:25 -04:00
|
|
|
/**
|
|
|
|
|
* Activate a plugin with your name
|
|
|
|
|
* @param string $Namespace
|
|
|
|
|
* @return int
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2017-08-01 12:16:06 -04:00
|
|
|
public static function enable($Namespace)
|
|
|
|
|
{
|
|
|
|
|
$oConnection = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME);
|
|
|
|
|
try {
|
|
|
|
|
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK(md5($Namespace));
|
|
|
|
|
if ($oPluginsRegistry) {
|
|
|
|
|
$oPluginsRegistry->fromArray(['PLUGIN_ENABLE' => true], BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
if ($oPluginsRegistry->validate()) {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$iResult = $oPluginsRegistry->save();
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return $iResult;
|
|
|
|
|
} else {
|
|
|
|
|
$sMessage = '';
|
|
|
|
|
$aValidationFailures = $oPluginsRegistry->getValidationFailures();
|
|
|
|
|
/** @var ValidationFailed $oValidationFailure */
|
|
|
|
|
foreach ($aValidationFailures as $oValidationFailure) {
|
|
|
|
|
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
|
|
|
|
}
|
|
|
|
|
throw (new Exception('The registry cannot be updated!<br />' . $sMessage));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception('This Plugin doesn\'t exist!'));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 09:32:25 -04:00
|
|
|
/**
|
|
|
|
|
* Disable a plugin with your name
|
|
|
|
|
* @param string $Namespace
|
|
|
|
|
* @return int
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2017-08-01 12:16:06 -04:00
|
|
|
public static function disable($Namespace)
|
|
|
|
|
{
|
|
|
|
|
$oConnection = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME);
|
|
|
|
|
try {
|
|
|
|
|
$oPluginsRegistry = PluginsRegistryPeer::retrieveByPK(md5($Namespace));
|
|
|
|
|
if ($oPluginsRegistry) {
|
|
|
|
|
$oPluginsRegistry->fromArray(['PLUGIN_ENABLE' => false], BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
if ($oPluginsRegistry->validate()) {
|
|
|
|
|
$oConnection->begin();
|
|
|
|
|
$iResult = $oPluginsRegistry->save();
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return $iResult;
|
|
|
|
|
} else {
|
|
|
|
|
$sMessage = '';
|
|
|
|
|
$aValidationFailures = $oPluginsRegistry->getValidationFailures();
|
|
|
|
|
/** @var ValidationFailed $oValidationFailure */
|
|
|
|
|
foreach ($aValidationFailures as $oValidationFailure) {
|
|
|
|
|
$sMessage .= $oValidationFailure->getMessage() . '<br />';
|
|
|
|
|
}
|
|
|
|
|
throw (new Exception('The registry cannot be updated!<br />' . $sMessage));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception('This Plugin doesn\'t exist!'));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-21 16:56:44 -04:00
|
|
|
}
|