@@ -1475,105 +1475,6 @@ public static function loadRepositoryDriver()
1475
1475
{
1476
1476
return self ::getInstance ()->loadRepositoryDriverInst ();
1477
1477
}
1478
- /**
1479
- * See static method
1480
- * @throws Exception
1481
- * @return AJXP_Plugin
1482
- */
1483
- public function loadRepositoryDriverInst ()
1484
- {
1485
- if (isSet ($ this ->configs ["ACCESS_DRIVER " ]) && is_a ($ this ->configs ["ACCESS_DRIVER " ], "AbstractAccessDriver " )) {
1486
- return $ this ->configs ["ACCESS_DRIVER " ];
1487
- }
1488
- $ this ->switchRootDirInst ();
1489
- $ crtRepository = $ this ->getRepositoryInst ();
1490
- if ($ crtRepository == null ){
1491
- throw new Exception ("No active repository found for user! " );
1492
- }
1493
- $ accessType = $ crtRepository ->getAccessType ();
1494
- $ pServ = AJXP_PluginsService::getInstance ();
1495
- $ plugInstance = $ pServ ->getPluginByTypeName ("access " , $ accessType );
1496
-
1497
- // TRIGGER BEFORE INIT META
1498
- $ metaSources = $ crtRepository ->getOption ("META_SOURCES " );
1499
- if (isSet ($ metaSources ) && is_array ($ metaSources ) && count ($ metaSources )) {
1500
- $ keys = array_keys ($ metaSources );
1501
- foreach ($ keys as $ plugId ) {
1502
- if ($ plugId == "" ) continue ;
1503
- $ split = explode (". " , $ plugId );
1504
- $ instance = $ pServ ->getPluginById ($ plugId );
1505
- if (!is_object ($ instance )) {
1506
- continue ;
1507
- }
1508
- if (!method_exists ($ instance , "beforeInitMeta " )) {
1509
- continue ;
1510
- }
1511
- try {
1512
- $ instance ->init (AuthService::filterPluginParameters ($ plugId , $ metaSources [$ plugId ], $ crtRepository ->getId ()));
1513
- $ instance ->beforeInitMeta ($ plugInstance , $ crtRepository );
1514
- } catch (Exception $ e ) {
1515
- AJXP_Logger::error (__CLASS__ , 'Meta plugin ' , 'Cannot instanciate Meta plugin, reason : ' .$ e ->getMessage ());
1516
- $ this ->errors [] = $ e ->getMessage ();
1517
- }
1518
- }
1519
- }
1520
-
1521
- // INIT MAIN DRIVER
1522
- $ plugInstance ->init ($ crtRepository );
1523
- try {
1524
- $ plugInstance ->initRepository ();
1525
- $ crtRepository ->driverInstance = $ plugInstance ;
1526
- } catch (Exception $ e ) {
1527
- // Remove repositories from the lists
1528
- $ this ->removeRepositoryFromCache ($ crtRepository ->getId ());
1529
- if (isSet ($ _SESSION ["PREVIOUS_REPO_ID " ]) && $ _SESSION ["PREVIOUS_REPO_ID " ] !=$ crtRepository ->getId ()) {
1530
- $ this ->switchRootDir ($ _SESSION ["PREVIOUS_REPO_ID " ]);
1531
- } else {
1532
- $ this ->switchRootDir ();
1533
- }
1534
- throw $ e ;
1535
- }
1536
- $ pServ ->setPluginUniqueActiveForType ("access " , $ accessType );
1537
-
1538
- // TRIGGER INIT META
1539
- $ metaSources = $ crtRepository ->getOption ("META_SOURCES " );
1540
- if (isSet ($ metaSources ) && is_array ($ metaSources ) && count ($ metaSources )) {
1541
- $ keys = array_keys ($ metaSources );
1542
- foreach ($ keys as $ plugId ) {
1543
- if ($ plugId == "" ) continue ;
1544
- $ split = explode (". " , $ plugId );
1545
- $ instance = $ pServ ->getPluginById ($ plugId );
1546
- if (!is_object ($ instance )) {
1547
- continue ;
1548
- }
1549
- try {
1550
- $ instance ->init (AuthService::filterPluginParameters ($ plugId , $ metaSources [$ plugId ], $ crtRepository ->getId ()));
1551
- if (!method_exists ($ instance , "initMeta " )) {
1552
- throw new Exception ("Meta Source $ plugId does not implement the initMeta method. " );
1553
- }
1554
- $ instance ->initMeta ($ plugInstance );
1555
- } catch (Exception $ e ) {
1556
- AJXP_Logger::error (__CLASS__ , 'Meta plugin ' , 'Cannot instanciate Meta plugin, reason : ' .$ e ->getMessage ());
1557
- $ this ->errors [] = $ e ->getMessage ();
1558
- }
1559
- $ pServ ->setPluginActive ($ split [0 ], $ split [1 ]);
1560
- }
1561
- }
1562
- if (count ($ this ->errors )>0 ) {
1563
- $ e = new AJXP_Exception ("Error while loading repository feature : " .implode (", " ,$ this ->errors ));
1564
- // Remove repositories from the lists
1565
- $ this ->removeRepositoryFromCache ($ crtRepository ->getId ());
1566
- if (isSet ($ _SESSION ["PREVIOUS_REPO_ID " ]) && $ _SESSION ["PREVIOUS_REPO_ID " ] !=$ crtRepository ->getId ()) {
1567
- $ this ->switchRootDir ($ _SESSION ["PREVIOUS_REPO_ID " ]);
1568
- } else {
1569
- $ this ->switchRootDir ();
1570
- }
1571
- throw $ e ;
1572
- }
1573
-
1574
- $ this ->configs ["ACCESS_DRIVER " ] = $ plugInstance ;
1575
- return $ this ->configs ["ACCESS_DRIVER " ];
1576
- }
1577
1478
1578
1479
/**
1579
1480
* @static
@@ -1582,20 +1483,36 @@ public function loadRepositoryDriverInst()
1582
1483
*/
1583
1484
public static function loadDriverForRepository (&$ repository )
1584
1485
{
1585
- return self ::getInstance ()->loadRepositoryDriverREST ($ repository );
1486
+ return self ::getInstance ()->loadRepositoryDriverInst ($ repository );
1586
1487
}
1587
1488
1588
1489
/**
1589
1490
* See static method
1590
- * @param Repository $repository
1491
+ * @param Repository|null $repository
1591
1492
* @throws AJXP_Exception|Exception
1592
1493
* @return AbstractAccessDriver
1593
1494
*/
1594
- public function loadRepositoryDriverREST (&$ repository )
1495
+ private function loadRepositoryDriverInst (&$ repository = null )
1595
1496
{
1596
- if (isset ($ repository ->driverInstance )) {
1597
- return $ repository ->driverInstance ;
1497
+ $ rest = false ;
1498
+ if ($ repository == null ){
1499
+ if (isSet ($ this ->configs ["ACCESS_DRIVER " ]) && is_a ($ this ->configs ["ACCESS_DRIVER " ], "AbstractAccessDriver " )) {
1500
+ return $ this ->configs ["ACCESS_DRIVER " ];
1501
+ }
1502
+ $ this ->switchRootDirInst ();
1503
+ $ repository = $ this ->getRepositoryInst ();
1504
+ if ($ repository == null ){
1505
+ throw new Exception ("No active repository found for user! " );
1506
+ }
1507
+ }else {
1508
+ $ rest = true ;
1509
+ if (isset ($ repository ->driverInstance )) {
1510
+ return $ repository ->driverInstance ;
1511
+ }
1598
1512
}
1513
+ /**
1514
+ * @var AbstractAccessDriver $plugInstance
1515
+ */
1599
1516
$ accessType = $ repository ->getAccessType ();
1600
1517
$ pServ = AJXP_PluginsService::getInstance ();
1601
1518
$ plugInstance = $ pServ ->getPluginByTypeName ("access " , $ accessType );
@@ -1627,9 +1544,20 @@ public function loadRepositoryDriverREST(&$repository)
1627
1544
$ plugInstance ->init ($ repository );
1628
1545
try {
1629
1546
$ plugInstance ->initRepository ();
1547
+ $ repository ->driverInstance = $ plugInstance ;
1630
1548
} catch (Exception $ e ) {
1549
+ if (!$ rest ){
1550
+ // Remove repositories from the lists
1551
+ $ this ->removeRepositoryFromCache ($ repository ->getId ());
1552
+ if (isSet ($ _SESSION ["PREVIOUS_REPO_ID " ]) && $ _SESSION ["PREVIOUS_REPO_ID " ] !=$ repository ->getId ()) {
1553
+ $ this ->switchRootDir ($ _SESSION ["PREVIOUS_REPO_ID " ]);
1554
+ } else {
1555
+ $ this ->switchRootDir ();
1556
+ }
1557
+ }
1631
1558
throw $ e ;
1632
1559
}
1560
+
1633
1561
AJXP_PluginsService::deferBuildingRegistry ();
1634
1562
$ pServ ->setPluginUniqueActiveForType ("access " , $ accessType );
1635
1563
@@ -1646,7 +1574,9 @@ public function loadRepositoryDriverREST(&$repository)
1646
1574
}
1647
1575
try {
1648
1576
$ instance ->init (AuthService::filterPluginParameters ($ plugId , $ metaSources [$ plugId ], $ repository ->getId ()));
1649
- if (!method_exists ($ instance , "initMeta " )) throw new Exception ("Meta Source $ plugId does not implement the initMeta method. " );
1577
+ if (!method_exists ($ instance , "initMeta " )) {
1578
+ throw new Exception ("Meta Source $ plugId does not implement the initMeta method. " );
1579
+ }
1650
1580
$ instance ->initMeta ($ plugInstance );
1651
1581
} catch (Exception $ e ) {
1652
1582
AJXP_Logger::error (__CLASS__ , 'Meta plugin ' , 'Cannot instanciate Meta plugin, reason : ' .$ e ->getMessage ());
@@ -1658,14 +1588,25 @@ public function loadRepositoryDriverREST(&$repository)
1658
1588
AJXP_PluginsService::flushDeferredRegistryBuilding ();
1659
1589
if (count ($ this ->errors )>0 ) {
1660
1590
$ e = new AJXP_Exception ("Error while loading repository feature : " .implode (", " ,$ this ->errors ));
1591
+ if (!$ rest ){
1592
+ // Remove repositories from the lists
1593
+ $ this ->removeRepositoryFromCache ($ repository ->getId ());
1594
+ if (isSet ($ _SESSION ["PREVIOUS_REPO_ID " ]) && $ _SESSION ["PREVIOUS_REPO_ID " ] !=$ repository ->getId ()) {
1595
+ $ this ->switchRootDir ($ _SESSION ["PREVIOUS_REPO_ID " ]);
1596
+ } else {
1597
+ $ this ->switchRootDir ();
1598
+ }
1599
+ }
1661
1600
throw $ e ;
1662
1601
}
1663
-
1664
- $ repository ->driverInstance = $ plugInstance ;
1665
- $ ctxId = $ this ->getContextRepositoryId ();
1666
- if (!empty ($ ctxId ) && $ ctxId == $ repository ->getId ()) {
1667
- $ this ->configs ["REPOSITORY " ] = $ repository ;
1668
- $ this ->cacheRepository ($ ctxId , $ repository );
1602
+ if ($ rest ){
1603
+ $ ctxId = $ this ->getContextRepositoryId ();
1604
+ if (!empty ($ ctxId ) && $ ctxId == $ repository ->getId ()) {
1605
+ $ this ->configs ["REPOSITORY " ] = $ repository ;
1606
+ $ this ->cacheRepository ($ ctxId , $ repository );
1607
+ }
1608
+ } else {
1609
+ $ this ->configs ["ACCESS_DRIVER " ] = $ plugInstance ;
1669
1610
}
1670
1611
return $ plugInstance ;
1671
1612
}
0 commit comments