-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration script to delete unnecessary shared_folders for OFAJ - …
…refs BT#21680
- Loading branch information
1 parent
9e807f8
commit 46ed216
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/CoreBundle/Migrations/Schema/V200/Version20240602231700.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; | ||
|
||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; | ||
use Chamilo\CourseBundle\Repository\CDocumentRepository; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\DBAL\ParameterType; | ||
|
||
final class Version20240602231700 extends AbstractMigrationChamilo | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Delete documents based on resource_node_id'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$documentRepo = $this->container->get(CDocumentRepository::class); | ||
|
||
$resourceNodeIds = [6027, 6029, 6030, 6035, 6031, 6028, 6034, 6036, 6024, 6032, 6275, 6270, 6274, 6272, 6269, 6277, 6268, 6187, 6189, 6025, 6188, 6271, 6273, 6396, 6276, 6192, 6191, 6394, 6391, 6398, 6193, 6033, 6393, 6385, 6186, 6386, 6389, 6390, 6400, 6387, 6392, 6399, 6397, 6395, 6388, 6701, 6702, 6696, 6703, 6278, 6695, 6699, 6700, 6803, 6801, 6698, 6190, 6809, 6810, 6802, 6705, 6039, 6697, 6811, 6804, 6807, 6984, 6959, 6961, 6805, 6958, 6964, 6956, 6963, 6985, 6965, 6806, 6986, 6953, 6957, 6962, 6960, 6954, 6951, 6955, 6952, 6038, 6041, 6026, 6052, 6057, 6047, 6055, 6059, 6056, 6050, 6053, 6054, 6042, 6048, 6294, 6043, 6046, 6285, 6280, 6292, 6044, 6290, 6288, 6201, 6198, 6286, 6289, 6291, 6287, 6293, 6283, 6282, 6402, 6404, 6411, 6409, 6416, 6405, 6412, 6407, 6408, 6419, 6413, 6281, 6195, 6403, 6707, 6410, 6716, 6414, 6284, 6711, 6714, 6417, 6704, 6708, 6720, 6418, 6060, 6713, 6196, 6406, 6710, 6709, 8636, 6415, 6717, 6718, 6045, 6712, 6197, 8638, 6199, 8640, 9329, 6058, 6970, 6978, 6969, 6982, 6976, 6968, 6975, 10611, 6967, 6980, 10610, 6049, 8644, 9333, 6973, 6719, 6200, 6981, 9331, 9332, 6051, 6715, 10271, 10272, 6972, 6977, 6983, 8646, 6979, 6966, 6974, 8643, 6971, 8645, 8651, 8649, 11173, 11171, 8653, 8654, 8650, 11176, 11175, 11178, 8656, 9335, 8658, 9336, 10028, 9340, 9339, 8663, 8660, 9338, 10032, 8662, 8661, 8982, 8980, 8981, 8647, 10030, 8665, 8666, 10861, 10860, 10869, 10863, 10865, 10937, 10866, 11180, 10867, 10864, 10868, 10870, 10944, 10938, 10946, 10945, 10943, 10940, 10942, 10939, 10941, 10862, 14172, 14173, 9808, 11056, 11063, 11057, 11061, 11059, 11062, 11065, 11064, 11060, 11115, 11067, 11120, 11119, 11114, 11122, 11117, 11066, 13768, 9343, 8454, 13769, 11118, 11004, 8668, 9342, 11121, 9345, 14176, 14494, 14493, 11058, 14175, 11116, 9347, 8670, 8985, 8984, 6988, 10034, 8672, 10275, 9349, 8673, 10037, 10274, 10038, 10036, 13771, 14178, 14180, 13773, 14182, 14181, 13774, 13776, 14187, 14189, 14184, 6037, 14186, 14188, 14191, 9811, 9810, 6987, 15609, 15774, 13778, 15207, 8674, 14899, 10277, 15611, 14900, 8987, 9813, 15435, 11447, 15209, 15437, 15777, 15776, 8989, 14902, 15780, 15786, 15778, 14193, 8988, 15788, 15784, 15783, 14195, 13782, 13781, 14197, 15782, 13780, 13141, 14904, 13787, 14906, 13785, 13784, 12329, 10280, 15211, 15613, 14909, 13789, 10279, 9815, 11450, 14908, 14199, 14200, 13792, 11449, 14204, 15213, 14202, 11791, 16035, 10509, 10282, 10283, 13791, 14206, 14496, 14497, 14499, 15215, 15219, 10029, 15218, 11662, 13143, 14208, 15217, 8642, 11170, 9328, 9817, 15790, 14911, 13145, 14210, 10871, 9819, 16331, 13147, 13794, 13795, 14913, 11665, 11664, 13798, 11793, 10511, 10512, 14213, 14212, 14215, 16333, 13800, 6989, 15221, 17427, 17430, 11667, 15223, 17429, 15225, 11453, 11452, 18481, 15792, 13802, 10286, 10287, 10285, 17433, 9821, 16335, 9823, 14918, 14917, 14915, 14916, 13797, 15227, 14920, 11455, 17026, 14921, 9788, 6990, 13702, 16170, 6991, 17348, 10248, 10507, 17349, 10247, 11430, 14838, 14839, 10246, 13694, 14834, 14837, 17351, 13696, 14134, 14836, 13700, 13698, 13699, 14841, 9790, 13124, 17357, 17354, 17355, 10251, 10250, 14843, 14138, 14137, 14139, 14136, 9792, 9793, 13704, 13705, 11973, 14846, 12323, 11778, 14845, 14832, 15183, 11976, 15772, 11975, 15181, 10253, 14142, 14141, 9795, 14143, 14145, 13707, 17359, 9797, 17353, 14848, 17361, 14850, 6021, 6020, 6015, 6018, 6022, 6019, 14851, 6014, 6264, 6016, 17366, 6017, 6260, 17364, 6265, 17365, 17363, 18603, 18606, 18605, 18604, 18597, 18607, 18599, 6266, 18608, 6262, 13709, 14148, 6263, 10255, 14147, 6420, 6261, 6183, 18611, 18612, 6184, 13127, 6182, 13711, 6361, 14151, 6363, 6061, 17368, 6367, 6372, 6380, 13716, 13717, 14150, 6370, 6382, 6378, 6371, 6181, 6180, 17369, 6379, 6366, 6377, 6365, 6383, 6373, 13126, 6368, 6369, 13712, 6376, 6374, 6721, 6364, 6375, 6381, 6691, 6678, 14855, 6685, 12560, 6673, 6684, 6682, 6681, 14857, 6679, 18614, 6692, 6674, 6686, 6362, 13719, 6675, 6683, 6688, 6677, 15187, 14152, 14853, 14854, 18617, 6672, 17432, 6676, 6680, 17372, 14154, 11432, 17371, 13129, 13721, 6690, 6687, 9800, 18620, 18619, 18609, 14859, 6689, 10259, 17374, 15185, 6693, 17376, 13131, 17377, 11780, 11658, 6997, 11434, 6996, 7011, 7005, 7012, 7006, 7008, 13725, 18622, 11445, 7003, 6993, 18601, 6994, 10269, 13723, 7007, 18624, 14861, 7000, 6992, 17379, 13714, 9799, 7002, 14862, 18626, 16171, 17030, 7009, 6995, 7004, 18600, 18628, 11660, 7001, 10261, 16317, 15189, 11978, 6998, 17383, 13133, 6999, 16033, 13729, 13134, 13730, 18634, 18630, 15191, 18631, 18598, 18633, 14866, 17386, 17385, 14864, 14865, 18635, 9802, 13732, 18637, 17388, 17390, 13733, 14156, 10263, 15194, 16168, 10257, 12562, 17392, 15196, 15193, 15197, 17395, 17394, 13735, 15199, 18616, 9804, 7010, 18639, 13737, 13739, 18641, 17397, 13740, 17398, 14870, 15201, 14868, 14869, 17400, 12953, 17401, 18643, 13727, 12564, 14872, 11782, 14158, 17403, 10265, 11785, 18645, 11437, 11436, 13742, 16319, 17405, 11439, 11784, 17028, 14160, 18647, 13744, 15203, 13747, 13746, 14874, 19283, 13137, 13136, 10267, 13749, 17407, 14876, 16329, 16321, 14880, 13751, 17410, 17409, 14879, 14878, 13754, 13753, 13756, 14883, 14882, 11441, 17412, 20190, 16323, 17414, 14885, 15205, 12325, 11443, 14163, 14162, 14165, 11787, 14887, 14168, 17416, 14167, 14889, 17420, 13139, 17417, 13758, 13760, 17381, 12327, 17419, 13761, 13764, 14891, 9806, 13763, 14170, 17422, 16325, 14893, 14895, 13766, 17425, 17424, 11789, 14897, 16327]; | ||
|
||
$sql = 'SELECT iid FROM c_document WHERE resource_node_id IN (?)'; | ||
$result = $this->connection->executeQuery($sql, [$resourceNodeIds], [Connection::PARAM_INT_ARRAY]); | ||
$iids = $result->fetchAllAssociative(); | ||
|
||
if (empty($iids)) { | ||
echo 'No documents found to delete.' . PHP_EOL; | ||
} | ||
|
||
foreach ($iids as $itemData) { | ||
echo 'Deleting document with iid: ' . $itemData['iid'] . PHP_EOL; | ||
$document = $documentRepo->find($itemData['iid']); | ||
if ($document) { | ||
if ($document->getResourceNode()) { | ||
$this->entityManager->remove($document->getResourceNode()); | ||
} | ||
$this->entityManager->remove($document); | ||
echo 'Deleted document with iid: ' . $itemData['iid'] . PHP_EOL; | ||
} else { | ||
echo 'Document with iid ' . $itemData['iid'] . ' not found.' . PHP_EOL; | ||
} | ||
} | ||
|
||
$this->entityManager->flush(); | ||
$this->entityManager->clear(); | ||
} | ||
} |