Plugin: Don't copy entities to PluginBundle

pull/4140/head
Angel Fernando Quiroz Campos 4 years ago
parent 1a2284a55f
commit d20441e96a
  1. 2
      main/admin/settings.lib.php
  2. 26
      main/inc/lib/plugin.lib.php
  3. 74
      plugin/coursehomenotify/CourseHomeNotifyPlugin.php
  4. 73
      plugin/embedregistry/EmbedRegistryPlugin.php
  5. 165
      plugin/ims_lti/ImsLtiPlugin.php
  6. 107
      plugin/lti_provider/LtiProviderPlugin.php
  7. 65
      plugin/studentfollowup/StudentFollowUpPlugin.php
  8. 95
      plugin/whispeakauth/WhispeakAuthPlugin.php

@ -237,6 +237,8 @@ function handlePlugins()
echo Display::return_message(get_lang('SettingsStored'), 'confirmation');
}
AppPlugin::cleanEntitiesInBundle();
$all_plugins = $plugin_obj->read_plugins_from_path();
$installed_plugins = $plugin_obj->getInstalledPlugins();
$officialPlugins = $plugin_obj->getOfficialPlugins();

@ -884,4 +884,30 @@ class AppPlugin
return false;
}
public static function cleanEntitiesInBundle()
{
$pluginList = [
'CourseHomeNotify',
'EmbedRegistry',
'ImsLti',
'LtiProvider',
'StudentFollowUp',
'WhispeakAuth',
];
foreach ($pluginList as $pluginName) {
$entityPath = api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$pluginName;
if (!is_dir($entityPath)) {
continue;
}
if (!is_writable($entityPath)) {
continue;
}
rmdirr($entityPath);
}
}
}

@ -3,7 +3,7 @@
use Chamilo\PluginBundle\Entity\CourseHomeNotify\Notification;
use Chamilo\PluginBundle\Entity\CourseHomeNotify\NotificationRelUser;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Class CourseHomeNotifyPlugin.
@ -41,51 +41,24 @@ class CourseHomeNotifyPlugin extends Plugin
/**
* Install process.
* Create table in database. And setup Doctirne entity.
*
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function install()
{
$pluginEntityPath = $this->getEntityPath();
if (!is_dir($pluginEntityPath)) {
if (!is_writable(dirname($pluginEntityPath))) {
$message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath;
Display::addFlash(Display::return_message($message, 'error'));
return;
}
mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
}
$fs = new Filesystem();
$fs->mirror(__DIR__.'/Entity/', $pluginEntityPath, null, ['override']);
$schema = Database::getManager()->getConnection()->getSchemaManager();
if (false === $schema->tablesExist('course_home_notify_notification')) {
$sql = "CREATE TABLE course_home_notify_notification_rel_user (id INT AUTO_INCREMENT NOT NULL, notification_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_13E723DDEF1A9D84 (notification_id), INDEX IDX_13E723DDA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB";
Database::query($sql);
$sql = "CREATE TABLE course_home_notify_notification (id INT AUTO_INCREMENT NOT NULL, c_id INT NOT NULL, content LONGTEXT NOT NULL, expiration_link VARCHAR(255) NOT NULL, hash VARCHAR(255) NOT NULL, INDEX IDX_7C6C1B0191D79BD3 (c_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB";
Database::query($sql);
$sql = "ALTER TABLE course_home_notify_notification_rel_user ADD CONSTRAINT FK_13E723DDEF1A9D84 FOREIGN KEY (notification_id) REFERENCES course_home_notify_notification (id) ON DELETE CASCADE";
Database::query($sql);
$sql = "ALTER TABLE course_home_notify_notification_rel_user ADD CONSTRAINT FK_13E723DDA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE";
Database::query($sql);
$em = Database::getManager();
$sql = "ALTER TABLE course_home_notify_notification ADD CONSTRAINT FK_7C6C1B0191D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE";
Database::query($sql);
}
}
if ($em->getConnection()->getSchemaManager()->tablesExist(['course_home_notify_notification'])) {
return;
};
/**
* @return string
*/
public function getEntityPath()
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(
[
$em->getClassMetadata(Notification::class),
$em->getClassMetadata(NotificationRelUser::class),
]
);
}
/**
@ -94,18 +67,19 @@ class CourseHomeNotifyPlugin extends Plugin
*/
public function uninstall()
{
$pluginEntityPath = $this->getEntityPath();
$fs = new Filesystem();
$em = Database::getManager();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
if (!$em->getConnection()->getSchemaManager()->tablesExist(['course_home_notify_notification'])) {
return;
}
$table = Database::get_main_table('course_home_notify_notification_rel_user');
Database::query("DROP TABLE IF EXISTS $table");
$table = Database::get_main_table('course_home_notify_notification');
Database::query("DROP TABLE IF EXISTS $table");
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema(
[
$em->getClassMetadata(Notification::class),
$em->getClassMetadata(NotificationRelUser::class),
]
);
}
/**

@ -4,7 +4,7 @@
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\PluginBundle\Entity\EmbedRegistry\Embed;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Class EmbedRegistryPlugin.
@ -60,41 +60,39 @@ class EmbedRegistryPlugin extends Plugin
return $result ? $result : $result = new self();
}
/**
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function install()
{
$entityPath = $this->getEntityPath();
if (!is_dir($entityPath)) {
if (!is_writable(dirname($entityPath))) {
Display::addFlash(
Display::return_message(
get_lang('ErrorCreatingDir').' '.$entityPath,
'error'
)
);
return false;
}
$em = Database::getManager();
mkdir($entityPath, api_get_permissions_for_new_directories());
if ($em->getConnection()->getSchemaManager()->tablesExist([self::TBL_EMBED])) {
return;
}
$fs = new Filesystem();
$fs->mirror(__DIR__.'/Entity/', $entityPath, null, ['override']);
$this->createPluginTables();
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(
[
$em->getClassMetadata(Embed::class),
]
);
}
public function uninstall()
{
$entityPath = $this->getEntityPath();
$fs = new Filesystem();
$em = Database::getManager();
if ($fs->exists($entityPath)) {
$fs->remove($entityPath);
if (!$em->getConnection()->getSchemaManager()->tablesExist([self::TBL_EMBED])) {
return;
}
Database::query('DROP TABLE IF EXISTS '.self::TBL_EMBED);
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema(
[
$em->getClassMetadata(Embed::class),
]
);
}
/**
@ -243,33 +241,6 @@ class EmbedRegistryPlugin extends Plugin
Database::insert($tableAccess, $params);
}
private function createPluginTables()
{
$connection = Database::getManager()->getConnection();
if ($connection->getSchemaManager()->tablesExist(self::TBL_EMBED)) {
return;
}
$queries = [
'CREATE TABLE plugin_embed_registry_embed (id INT AUTO_INCREMENT NOT NULL, c_id INT NOT NULL, session_id INT DEFAULT NULL, title LONGTEXT NOT NULL, display_start_date DATETIME NOT NULL, display_end_date DATETIME NOT NULL, html_code LONGTEXT NOT NULL, INDEX IDX_5236D25991D79BD3 (c_id), INDEX IDX_5236D259613FECDF (session_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
'ALTER TABLE plugin_embed_registry_embed ADD CONSTRAINT FK_5236D25991D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)',
'ALTER TABLE plugin_embed_registry_embed ADD CONSTRAINT FK_5236D259613FECDF FOREIGN KEY (session_id) REFERENCES session (id)',
];
foreach ($queries as $query) {
Database::query($query);
}
}
/**
* @return string
*/
private function getEntityPath()
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
}
private function deleteCourseToolLinks()
{
Database::getManager()

@ -6,10 +6,11 @@ use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\PluginBundle\Entity\ImsLti\ImsLtiTool;
use Chamilo\PluginBundle\Entity\ImsLti\LineItem;
use Chamilo\PluginBundle\Entity\ImsLti\Platform;
use Chamilo\PluginBundle\Entity\ImsLti\Token;
use Chamilo\UserBundle\Entity\User;
use Doctrine\DBAL\DBALException;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Description of MsiLti.
@ -63,25 +64,11 @@ class ImsLtiPlugin extends Plugin
/**
* Install the plugin. Setup the database.
*
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function install()
{
$pluginEntityPath = $this->getEntityPath();
if (!is_dir($pluginEntityPath)) {
if (!is_writable(dirname($pluginEntityPath))) {
$message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath;
Display::addFlash(Display::return_message($message, 'error'));
return false;
}
mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
}
$fs = new Filesystem();
$fs->mirror(__DIR__.'/Entity/', $pluginEntityPath, null, ['override']);
$this->createPluginTables();
}
@ -131,17 +118,10 @@ class ImsLtiPlugin extends Plugin
*/
public function uninstall()
{
$pluginEntityPath = $this->getEntityPath();
$fs = new Filesystem();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
}
try {
$this->dropPluginTables();
$this->removeTools();
} catch (DBALException $e) {
} catch (Exception $e) {
error_log('Error while uninstalling IMS/LTI plugin: '.$e->getMessage());
}
}
@ -237,14 +217,6 @@ class ImsLtiPlugin extends Plugin
$em->flush();
}
/**
* @return string
*/
public function getEntityPath()
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
}
public static function isInstructor()
{
api_is_allowed_to_edit(false, true);
@ -628,116 +600,47 @@ class ImsLtiPlugin extends Plugin
/**
* Creates the plugin tables on database.
*
* @throws DBALException
*
* @return bool
* @throws \Doctrine\ORM\Tools\ToolsException
*/
private function createPluginTables()
{
$entityManager = Database::getManager();
$connection = $entityManager->getConnection();
if ($connection->getSchemaManager()->tablesExist(self::TABLE_TOOL)) {
return true;
}
$queries = [
"CREATE TABLE plugin_ims_lti_tool (
id INT AUTO_INCREMENT NOT NULL,
c_id INT DEFAULT NULL,
gradebook_eval_id INT DEFAULT NULL,
parent_id INT DEFAULT NULL,
name VARCHAR(255) NOT NULL,
description LONGTEXT DEFAULT NULL,
launch_url VARCHAR(255) NOT NULL,
consumer_key VARCHAR(255) DEFAULT NULL,
shared_secret VARCHAR(255) DEFAULT NULL,
custom_params LONGTEXT DEFAULT NULL,
active_deep_linking TINYINT(1) DEFAULT '0' NOT NULL,
privacy LONGTEXT DEFAULT NULL,
client_id VARCHAR(255) DEFAULT NULL,
public_key LONGTEXT DEFAULT NULL,
login_url VARCHAR(255) DEFAULT NULL,
redirect_url VARCHAR(255) DEFAULT NULL,
advantage_services LONGTEXT DEFAULT NULL COMMENT '(DC2Type:json)',
version VARCHAR(255) DEFAULT 'lti1p1' NOT NULL,
launch_presentation LONGTEXT NOT NULL COMMENT '(DC2Type:json)',
replacement_params LONGTEXT NOT NULL COMMENT '(DC2Type:json)',
session_id INT DEFAULT NULL,
INDEX IDX_C5E47F7C91D79BD3 (c_id),
INDEX IDX_C5E47F7C82F80D8B (gradebook_eval_id),
INDEX IDX_C5E47F7C727ACA70 (parent_id),
INDEX IDX_C5E47F7C613FECDF (session_id),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
"CREATE TABLE plugin_ims_lti_platform (
id INT AUTO_INCREMENT NOT NULL,
kid VARCHAR(255) NOT NULL,
public_key LONGTEXT NOT NULL,
private_key LONGTEXT NOT NULL,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
"CREATE TABLE plugin_ims_lti_token (
id INT AUTO_INCREMENT NOT NULL,
tool_id INT DEFAULT NULL,
scope LONGTEXT NOT NULL COMMENT '(DC2Type:json)',
hash VARCHAR(255) NOT NULL,
created_at INT NOT NULL,
expires_at INT NOT NULL,
INDEX IDX_F7B5692F8F7B22CC (tool_id),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
"ALTER TABLE plugin_ims_lti_tool
ADD CONSTRAINT FK_C5E47F7C91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)",
"ALTER TABLE plugin_ims_lti_tool
ADD CONSTRAINT FK_C5E47F7C82F80D8B FOREIGN KEY (gradebook_eval_id)
REFERENCES gradebook_evaluation (id) ON DELETE SET NULL",
"ALTER TABLE plugin_ims_lti_tool
ADD CONSTRAINT FK_C5E47F7C727ACA70 FOREIGN KEY (parent_id)
REFERENCES plugin_ims_lti_tool (id) ON DELETE CASCADE",
"ALTER TABLE plugin_ims_lti_token
ADD CONSTRAINT FK_F7B5692F8F7B22CC FOREIGN KEY (tool_id)
REFERENCES plugin_ims_lti_tool (id) ON DELETE CASCADE",
"CREATE TABLE plugin_ims_lti_lineitem (
id INT AUTO_INCREMENT NOT NULL,
tool_id INT NOT NULL,
evaluation INT NOT NULL,
resource_id VARCHAR(255) DEFAULT NULL,
tag VARCHAR(255) DEFAULT NULL,
start_date DATETIME DEFAULT NULL,
end_date DATETIME DEFAULT NULL,
INDEX IDX_BA81BBF08F7B22CC (tool_id),
UNIQUE INDEX UNIQ_BA81BBF01323A575 (evaluation),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
"ALTER TABLE plugin_ims_lti_lineitem ADD CONSTRAINT FK_BA81BBF08F7B22CC FOREIGN KEY (tool_id)
REFERENCES plugin_ims_lti_tool (id) ON DELETE CASCADE",
"ALTER TABLE plugin_ims_lti_lineitem ADD CONSTRAINT FK_BA81BBF01323A575 FOREIGN KEY (evaluation)
REFERENCES gradebook_evaluation (id) ON DELETE CASCADE ",
"ALTER TABLE plugin_ims_lti_tool ADD CONSTRAINT FK_C5E47F7C613FECDF FOREIGN KEY (session_id)
REFERENCES session (id)",
];
$em = Database::getManager();
foreach ($queries as $query) {
Database::query($query);
}
if ($em->getConnection()->getSchemaManager()->tablesExist([self::TABLE_TOOL])) {
return;
};
return true;
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(
[
$em->getClassMetadata(ImsLtiTool::class),
$em->getClassMetadata(LineItem::class),
$em->getClassMetadata(Platform::class),
$em->getClassMetadata(Token::class),
]
);
}
/**
* Drops the plugin tables on database.
*
* @return bool
*/
private function dropPluginTables()
{
Database::query("DROP TABLE IF EXISTS plugin_ims_lti_lineitem");
Database::query("DROP TABLE IF EXISTS plugin_ims_lti_token");
Database::query("DROP TABLE IF EXISTS plugin_ims_lti_platform");
Database::query("DROP TABLE IF EXISTS plugin_ims_lti_tool");
$em = Database::getManager();
return true;
if (!$em->getConnection()->getSchemaManager()->tablesExist([self::TABLE_TOOL])) {
return;
};
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema(
[
$em->getClassMetadata(ImsLtiTool::class),
$em->getClassMetadata(LineItem::class),
$em->getClassMetadata(Platform::class),
$em->getClassMetadata(Token::class),
]
);
}
private function removeTools()

@ -3,9 +3,8 @@
use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
use Chamilo\PluginBundle\Entity\LtiProvider\PlatformKey;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\OptimisticLockException;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Description of LtiProvider.
@ -166,34 +165,24 @@ class LtiProviderPlugin extends Plugin
/**
* Install the plugin. Set the database up.
*
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function install()
{
$pluginEntityPath = $this->getEntityPath();
if (!is_dir($pluginEntityPath)) {
if (!is_writable(dirname($pluginEntityPath))) {
$message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath;
Display::addFlash(Display::return_message($message, 'error'));
return;
}
mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
}
$fs = new Filesystem();
$fs->mirror(__DIR__.'/Entity/', $pluginEntityPath, null, ['override']);
$em = Database::getManager();
$this->createPluginTables();
}
if ($em->getConnection()->getSchemaManager()->tablesExist(['sfu_post'])) {
return;
};
/**
* Get current entity sys path.
*/
public function getEntityPath(): string
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(
[
$em->getClassMetadata(Platform::class),
$em->getClassMetadata(PlatformKey::class),
]
);
}
/**
@ -243,18 +232,19 @@ class LtiProviderPlugin extends Plugin
*/
public function uninstall()
{
$pluginEntityPath = $this->getEntityPath();
$fs = new Filesystem();
$em = Database::getManager();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
}
if (!$em->getConnection()->getSchemaManager()->tablesExist(['sfu_post'])) {
return;
};
try {
$this->dropPluginTables();
} catch (DBALException $e) {
error_log('Error while uninstalling IMS/LTI plugin: '.$e->getMessage());
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema(
[
$em->getClassMetadata(Platform::class),
$em->getClassMetadata(PlatformKey::class),
]
);
}
public function trimParams(array &$params)
@ -265,42 +255,6 @@ class LtiProviderPlugin extends Plugin
}
}
/**
* Creates the plugin tables on database.
*/
private function createPluginTables(): void
{
if ($this->areTablesCreated()) {
return;
}
$queries = [
"CREATE TABLE plugin_lti_provider_platform (
id int NOT NULL AUTO_INCREMENT,
issuer varchar(255) NOT NULL,
client_id varchar(255) NOT NULL,
kid varchar(255) NOT NULL,
auth_login_url varchar(255) NOT NULL,
auth_token_url varchar(255) NOT NULL,
key_set_url varchar(255) NOT NULL,
deployment_id varchar(255) NOT NULL,
tool_provider varchar(255) NULL,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
"CREATE TABLE plugin_lti_provider_platform_key (
id INT AUTO_INCREMENT NOT NULL,
kid VARCHAR(255) NOT NULL,
public_key LONGTEXT NOT NULL,
private_key LONGTEXT NOT NULL,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB",
];
foreach ($queries as $query) {
Database::query($query);
}
}
private function areTablesCreated(): bool
{
$entityManager = Database::getManager();
@ -339,17 +293,6 @@ class LtiProviderPlugin extends Plugin
];
}
/**
* Drops the plugin tables on database.
*/
private function dropPluginTables(): bool
{
Database::query("DROP TABLE IF EXISTS plugin_lti_provider_platform");
Database::query("DROP TABLE IF EXISTS plugin_lti_provider_platform_key");
return true;
}
/**
* Get a SimpleXMLElement object with the request received on php://input.
*

@ -2,7 +2,8 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Symfony\Component\Filesystem\Filesystem;
use Chamilo\PluginBundle\Entity\StudentFollowUp\CarePost;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Class StudentFollowUpPlugin.
@ -35,53 +36,39 @@ class StudentFollowUpPlugin extends Plugin
return $result ? $result : $result = new self();
}
/**
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function install()
{
$pluginEntityPath = $this->getEntityPath();
if (!is_dir($pluginEntityPath)) {
if (!is_writable(dirname($pluginEntityPath))) {
$message = get_lang('ErrorCreatingDir').': '.$pluginEntityPath;
Display::addFlash(Display::return_message($message, 'error'));
return false;
}
mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
}
$em = Database::getManager();
$fs = new Filesystem();
$fs->mirror(__DIR__.'/Entity/', $pluginEntityPath, null, ['override']);
$schema = Database::getManager()->getConnection()->getSchemaManager();
if ($em->getConnection()->getSchemaManager()->tablesExist(['sfu_post'])) {
return;
};
if ($schema->tablesExist('sfu_post') === false) {
$sql = "CREATE TABLE IF NOT EXISTS sfu_post (id INT AUTO_INCREMENT NOT NULL, insert_user_id INT NOT NULL, user_id INT NOT NULL, parent_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, content LONGTEXT DEFAULT NULL, external_care_id VARCHAR(255) DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, private TINYINT(1) NOT NULL, external_source TINYINT(1) NOT NULL, tags LONGTEXT NOT NULL COMMENT '(DC2Type:array)', attachment VARCHAR(255) NOT NULL, lft INT DEFAULT NULL, rgt INT DEFAULT NULL, lvl INT DEFAULT NULL, root INT DEFAULT NULL, INDEX IDX_35F9473C9C859CC3 (insert_user_id), INDEX IDX_35F9473CA76ED395 (user_id), INDEX IDX_35F9473C727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;";
Database::query($sql);
$sql = "ALTER TABLE sfu_post ADD CONSTRAINT FK_35F9473C9C859CC3 FOREIGN KEY (insert_user_id) REFERENCES user (id);";
Database::query($sql);
$sql = "ALTER TABLE sfu_post ADD CONSTRAINT FK_35F9473CA76ED395 FOREIGN KEY (user_id) REFERENCES user (id);";
Database::query($sql);
$sql = "ALTER TABLE sfu_post ADD CONSTRAINT FK_35F9473C727ACA70 FOREIGN KEY (parent_id) REFERENCES sfu_post (id) ON DELETE SET NULL;";
Database::query($sql);
}
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(
[
$em->getClassMetadata(CarePost::class),
]
);
}
public function uninstall()
{
$pluginEntityPath = $this->getEntityPath();
$fs = new Filesystem();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
}
$table = Database::get_main_table('sfu_post');
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
}
$em = Database::getManager();
/**
* @return string
*/
public function getEntityPath()
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
if (!$em->getConnection()->getSchemaManager()->tablesExist(['sfu_post'])) {
return;
};
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema(
[
$em->getClassMetadata(CarePost::class),
]
);
}
/**

@ -7,7 +7,7 @@ use Chamilo\PluginBundle\Entity\WhispeakAuth\LogEvent;
use Chamilo\PluginBundle\Entity\WhispeakAuth\LogEventLp;
use Chamilo\PluginBundle\Entity\WhispeakAuth\LogEventQuiz;
use Chamilo\UserBundle\Entity\User;
use Symfony\Component\Filesystem\Filesystem;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Class WhispeakAuthPlugin.
@ -71,6 +71,9 @@ class WhispeakAuthPlugin extends Plugin implements HookPluginInterface
return $result ? $result : $result = new self();
}
/**
* @throws \Doctrine\ORM\Tools\ToolsException
*/
public function install()
{
$this->installExtraFields();
@ -85,14 +88,6 @@ class WhispeakAuthPlugin extends Plugin implements HookPluginInterface
$this->uninstallEntities();
}
/**
* @return string
*/
public function getEntityPath()
{
return api_get_path(SYS_PATH).'src/Chamilo/PluginBundle/Entity/'.$this->getCamelCaseName();
}
/**
* @return ExtraField
*/
@ -726,63 +721,24 @@ class WhispeakAuthPlugin extends Plugin implements HookPluginInterface
/**
* Install the Doctrine's entities.
* @throws \Doctrine\ORM\Tools\ToolsException
*/
private function installEntities()
{
$pluginEntityPath = $this->getEntityPath();
if (!is_dir($pluginEntityPath)) {
if (!is_writable(dirname($pluginEntityPath))) {
Display::addFlash(
Display::return_message(get_lang('ErrorCreatingDir').": $pluginEntityPath", 'error')
);
return;
}
$em = Database::getManager();
mkdir($pluginEntityPath, api_get_permissions_for_new_directories());
if ($em->getConnection()->getSchemaManager()->tablesExist(['whispeak_log_event'])) {
return;
}
$fs = new Filesystem();
$fs->mirror(__DIR__.'/Entity/', $pluginEntityPath, null, ['override']);
$schema = Database::getManager()->getConnection()->getSchemaManager();
if (false === $schema->tablesExist('whispeak_log_event')) {
$sql = "CREATE TABLE whispeak_log_event (
id INT AUTO_INCREMENT NOT NULL,
user_id INT NOT NULL,
lp_item_id INT DEFAULT NULL,
lp_id INT DEFAULT NULL,
question_id INT DEFAULT NULL,
quiz_id INT DEFAULT NULL,
datetime DATETIME NOT NULL,
action_status SMALLINT NOT NULL,
discr VARCHAR(255) NOT NULL,
INDEX IDX_A5C4B9FFA76ED395 (user_id),
INDEX IDX_A5C4B9FFDBF72317 (lp_item_id),
INDEX IDX_A5C4B9FF68DFD1EF (lp_id),
INDEX IDX_A5C4B9FF1E27F6BF (question_id),
INDEX IDX_A5C4B9FF853CD175 (quiz_id),
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB";
Database::query($sql);
$sql = "ALTER TABLE whispeak_log_event ADD CONSTRAINT FK_A5C4B9FFA76ED395
FOREIGN KEY (user_id) REFERENCES user (id)";
Database::query($sql);
$sql = "ALTER TABLE whispeak_log_event ADD CONSTRAINT FK_A5C4B9FFDBF72317
FOREIGN KEY (lp_item_id) REFERENCES c_lp_item (iid)";
Database::query($sql);
$sql = "ALTER TABLE whispeak_log_event ADD CONSTRAINT FK_A5C4B9FF68DFD1EF
FOREIGN KEY (lp_id) REFERENCES c_lp (iid)";
Database::query($sql);
$sql = "ALTER TABLE whispeak_log_event ADD CONSTRAINT FK_A5C4B9FF1E27F6BF
FOREIGN KEY (question_id) REFERENCES c_quiz_question (iid)";
Database::query($sql);
$sql = "ALTER TABLE whispeak_log_event ADD CONSTRAINT FK_A5C4B9FF853CD175
FOREIGN KEY (quiz_id) REFERENCES c_quiz (iid)";
Database::query($sql);
}
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema(
[
$em->getClassMetadata(LogEvent::class),
$em->getClassMetadata(LogEventLp::class),
$em->getClassMetadata(LogEventQuiz::class),
]
);
}
/**
@ -831,16 +787,19 @@ class WhispeakAuthPlugin extends Plugin implements HookPluginInterface
*/
private function uninstallEntities()
{
$pluginEntityPath = $this->getEntityPath();
$fs = new Filesystem();
$em = Database::getManager();
if ($fs->exists($pluginEntityPath)) {
$fs->remove($pluginEntityPath);
if (!$em->getConnection()->getSchemaManager()->tablesExist(['whispeak_log_event'])) {
return;
}
$table = Database::get_main_table('whispeak_log_event');
$sql = "DROP TABLE IF EXISTS $table";
Database::query($sql);
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema(
[
$em->getClassMetadata(LogEvent::class),
$em->getClassMetadata(LogEventLp::class),
$em->getClassMetadata(LogEventQuiz::class),
]
);
}
}

Loading…
Cancel
Save