commit
2c125c3990
@ -0,0 +1,36 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
final class Version20240114215900 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Modify track_e_downloads table structure'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
$this->addSql('DROP INDEX idx_ted_c_id ON track_e_downloads;'); |
||||
$this->addSql('DROP INDEX down_session_id ON track_e_downloads;'); |
||||
$this->addSql('ALTER TABLE track_e_downloads ADD resource_link_id INT DEFAULT NULL, DROP c_id, DROP down_session_id;'); |
||||
$this->addSql('ALTER TABLE track_e_downloads ADD CONSTRAINT FK_EEDF4DA6F004E599 FOREIGN KEY (resource_link_id) REFERENCES resource_link (id) ON DELETE SET NULL;'); |
||||
$this->addSql('CREATE INDEX IDX_EEDF4DA6F004E599 ON track_e_downloads (resource_link_id);'); |
||||
} |
||||
|
||||
public function down(Schema $schema): void |
||||
{ |
||||
$this->addSql('ALTER TABLE track_e_downloads DROP FOREIGN KEY FK_EEDF4DA6F004E599;'); |
||||
$this->addSql('DROP INDEX IDX_EEDF4DA6F004E599 ON track_e_downloads;'); |
||||
$this->addSql('ALTER TABLE track_e_downloads DROP resource_link_id;'); |
||||
$this->addSql('ALTER TABLE track_e_downloads ADD c_id INT NOT NULL;'); |
||||
$this->addSql('ALTER TABLE track_e_downloads ADD down_session_id INT DEFAULT NULL;'); |
||||
$this->addSql('CREATE INDEX idx_ted_c_id ON track_e_downloads (c_id);'); |
||||
$this->addSql('CREATE INDEX down_session_id ON track_e_downloads (down_session_id);'); |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\ResourceLink; |
||||
use Chamilo\CoreBundle\Entity\TrackEDownloads; |
||||
use DateTime; |
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
||||
use Doctrine\Persistence\ManagerRegistry; |
||||
|
||||
class TrackEDownloadsRepository extends ServiceEntityRepository |
||||
{ |
||||
public function __construct(ManagerRegistry $registry) |
||||
{ |
||||
parent::__construct($registry, TrackEDownloads::class); |
||||
} |
||||
|
||||
public function saveDownload(int $userId, int $resourceLinkId, string $documentUrl) |
||||
{ |
||||
$download = new TrackEDownloads(); |
||||
$download->setDownDocPath($documentUrl); |
||||
$download->setDownUserId($userId); |
||||
$download->setDownDate(new DateTime()); |
||||
|
||||
$resourceLink = $this->_em->getRepository(ResourceLink::class)->find($resourceLinkId); |
||||
if ($resourceLink) { |
||||
$download->setResourceLink($resourceLink); |
||||
} |
||||
|
||||
$this->_em->persist($download); |
||||
$this->_em->flush(); |
||||
|
||||
return $download->getDownId(); |
||||
} |
||||
} |
Loading…
Reference in new issue