Example #1
0
 function display($tpl = null)
 {
     // Get the url of the Alfresco repository from the Joosco plugin
     // That's why the Joosco plugin needs to be installed and configured before the component
     $plugin =& JPluginHelper::getPlugin('authentication', 'joosco');
     $pluginParams = new JParameter($plugin->params);
     // Here we connect to the Repository
     $repositoryUrl = $pluginParams->get('alf-url');
     $repository = new Repository($repositoryUrl);
     // The ticket is created by the plugin when a user connects
     $ticket = $_SESSION["ticket"];
     $session = $repository->createSession($ticket);
     $store = new SpacesStore($session);
     $currentNode = null;
     $uuid = null;
     $uuid =& JRequest::getVar('uuid');
     if (!isset($uuid)) {
         $currentNode = $store->companyHome;
         $path = 'Company Home';
     } else {
         $currentNode = $session->getNode($store, JRequest::getVar('uuid'));
         $path = JRequest::getVar('path') . '|' . JRequest::getVar('uuid') . '|' . JRequest::getVar('name');
     }
     // Pass the values to the rest of the template
     $this->assignRef('path', $path);
     $this->assignRef('session', $session);
     $this->assignRef('store', $store);
     $this->assignRef('currentNode', $currentNode);
     $this->assignRef('option', JRequest::getVar('option'));
     $this->assignRef('view', JRequest::getVar('view'));
     $this->assignRef('itemid', JRequest::getVar('Itemid'));
     parent::display($tpl);
 }
Example #2
0
 /**
  * Add the field to query to find the model
  *
  * @param Repository $repository
  *
  * @return Repository
  */
 public function searchRepository($repository, $value, $table = null)
 {
     if (!$table) {
         $table = $this->getObjectSchema()->getTable();
     }
     return $repository->orWhere($table . "." . $this->getColumn(), (int) $value);
 }
 /**
  * Constructor.
  *
  * @param Repository $repository
  */
 public function __construct(Repository $repository)
 {
     $this->repository = $repository;
     $this->manager = $repository->getManager();
     $this->metadata = $repository->getMetadata();
     $this->query = $this->manager->getConnection()->createQueryBuilder()->from($this->metadata->getTable());
 }
Example #4
0
 /**
  * Test Repository
  *
  * @param Repository $repo
  * @return Boolean
  */
 public function doRepositoryTest($repo)
 {
     if ($repo->accessType != 'fs') {
         return -1;
     }
     // Check the destination path
     $this->failedInfo = "";
     $safePath = $repo->getOption("PATH", true);
     if (strstr($safePath, "AJXP_USER") !== false) {
         return TRUE;
     }
     // CANNOT TEST THIS CASE!
     $path = $repo->getOption("PATH", false);
     $createOpt = $repo->getOption("CREATE");
     $create = $createOpt == "true" || $createOpt === true ? true : false;
     if (!$create && !@is_dir($path)) {
         $this->failedInfo .= "Selected repository path " . $path . " doesn't exist, and the CREATE option is false";
         return FALSE;
     }
     /* else if ($create && !is_writeable($path)) {
            $this->failedInfo .= "Selected repository path ".$path." isn't writeable"; return FALSE;
        }*/
     // Do more tests here
     return TRUE;
 }
 public function initRepository()
 {
     if (is_array($this->pluginConf)) {
         $this->driverConf = $this->pluginConf;
     } else {
         $this->driverConf = array();
     }
     $smbclientPath = $this->driverConf["SMBCLIENT"];
     define('SMB4PHP_SMBCLIENT', $smbclientPath);
     $smbtmpPath = $this->driverConf["SMB_PATH_TMP"];
     define('SMB4PHP_SMBTMP', $smbtmpPath);
     require_once $this->getBaseDir() . "/smb.php";
     $create = $this->repository->getOption("CREATE");
     $recycle = $this->repository->getOption("RECYCLE_BIN");
     $this->detectStreamWrapper(true);
     $this->urlBase = "pydio://" . $this->repository->getId();
     if ($recycle != "" && !is_dir($this->urlBase . "/" . $recycle)) {
         @mkdir($this->urlBase . "/" . $recycle);
         if (!is_dir($this->urlBase . "/" . $recycle)) {
             throw new AJXP_Exception("Cannot create recycle bin folder. Please check repository configuration or that your folder is writeable!");
         }
     }
     if ($recycle != "") {
         RecycleBinManager::init($this->urlBase, "/" . $recycle);
     }
 }
Example #6
0
 /**
  * Returns content of the blob.
  *
  * @throws ProcessException Error occurred while getting content of blob
  */
 public function getContent()
 {
     if (null === $this->content) {
         $this->content = $this->repository->run('cat-file', array('-p', $this->hash));
     }
     return $this->content;
 }
Example #7
0
 /**
  * This method should handle any authentication and report back to the subject
  *
  * @access	public
  * @param   array 	$credentials Array holding the user credentials	
  * @param 	array   $options     Array of extra options
  * @param	object	$response	Authentication response object
  * @return	boolean
  * @since 1.5
  */
 function onAuthenticate($credentials, $options, &$response)
 {
     // This file is needed to use the Repository class
     require_once dirname(__FILE__) . '/alfresco-php-library/Repository.php';
     // Get the URL of the Alfresco repository as a parameter of the plugin
     $plugin =& JPluginHelper::getPlugin('authentication', 'joosco');
     $pluginParams = new JParameter($plugin->params);
     // Set the variables
     $repositoryUrl = $pluginParams->get('alf-url');
     $userName = $credentials['username'];
     $password = $credentials['password'];
     // Connect to the repository
     $repository = new Repository($repositoryUrl);
     $ticket = null;
     try {
         // Try to create a ticket
         $ticket = $repository->authenticate($userName, $password);
         // If the ticket fails, it means that the username and/or password are wrong
         $_SESSION["ticket"] = $ticket;
         $response->status = JAUTHENTICATE_STATUS_SUCCESS;
         // There's no way to get the Alfresco name or email address of the user
         // The only thing to do is wait for an update of the Alfresco PHP API
         $response->username = $credentials['username'];
         $response->email = $credentials['username'] . "@alfresco.user";
         $response->fullname = $credentials['username'];
     } catch (Exception $e) {
         // Wrong username or password creates an exception
         $response->status = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = 'Authentication failed';
     }
 }
Example #8
0
 /**
  * Session constructor
  *
  * @param Repository $repository    The repository to log in
  * @param string     $workspaceName The workspace's name
  *
  * @api
  */
 public function __construct(Repository $repository, $workspaceName = null)
 {
     $this->repository = $repository;
     $parameters = $repository->getParameters();
     $credentials = new \PHPCR\SimpleCredentials($parameters['credentials.username'], $parameters['credentials.password']);
     $this->session = $repository->login($credentials, $workspaceName);
 }
Example #9
0
 /**
  * Send linkback on "create" events to remote repositories
  */
 public function send($event, Repository $repo)
 {
     if ($this->config === false) {
         return;
     }
     if ($event != 'create') {
         return;
     }
     $origin = $repo->getConnectionInfo()->getOrigin();
     if ($origin === null) {
         return;
     }
     $originWebUrl = $origin->getWebUrl(true);
     if ($originWebUrl === null) {
         return;
     }
     $this->pbc = new \PEAR2\Services\Linkback\Client();
     $req = $this->pbc->getRequest();
     $req->setConfig(array('ssl_verify_peer' => false, 'ssl_verify_host' => false));
     $this->pbc->setRequestTemplate($req);
     $req->setHeader('user-agent', 'phorkie');
     try {
         $res = $this->pbc->send($repo->getLink('display', null, true), $originWebUrl);
     } catch (\Exception $e) {
         //FIXME: log errors
     }
 }
 public function initRepository()
 {
     if (is_array($this->pluginConf)) {
         $this->driverConf = $this->pluginConf;
     } else {
         $this->driverConf = array();
     }
     if (!function_exists('ssh2_connect')) {
         throw new Exception("You must have the php ssh2 extension active!");
     }
     ConfService::setConf("PROBE_REAL_SIZE", false);
     $path = $this->repository->getOption("PATH");
     $recycle = $this->repository->getOption("RECYCLE_BIN");
     $this->detectStreamWrapper(true);
     $this->urlBase = "pydio://" . $this->repository->getId();
     restore_error_handler();
     if (!file_exists($this->urlBase)) {
         if ($this->repository->getOption("CREATE")) {
             $test = @mkdir($this->urlBase);
             if (!$test) {
                 throw new AJXP_Exception("Cannot create path ({$path}) for your repository! Please check the configuration.");
             }
         } else {
             throw new AJXP_Exception("Cannot find base path ({$path}) for your repository! Please check the configuration!");
         }
     }
     if ($recycle != "") {
         RecycleBinManager::init($this->urlBase, "/" . $recycle);
     }
 }
Example #11
0
 public function updateRepo(Repository $repo, $crdate = null, $modate = null)
 {
     //add repository
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'repo/' . $repo->id, \HTTP_Request2::METHOD_PUT);
     $repoData = array('id' => $repo->id, 'description' => $repo->getDescription(), 'tstamp' => gmdate('c', time()));
     if ($crdate == null) {
         $crdate = $this->getCrDate($repo);
     }
     if ($crdate !== null) {
         $repoData['crdate'] = gmdate('c', $crdate);
     }
     if ($modate == null) {
         $modate = $this->getMoDate($repo);
     }
     if ($modate !== null) {
         $repoData['modate'] = gmdate('c', $modate);
     }
     $r->setBody(json_encode((object) $repoData));
     $r->send();
     //add files
     //clean up before adding files; files might have been deleted
     $this->deleteRepoFiles($repo);
     foreach ($repo->getFiles() as $file) {
         $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'file/?parent=' . $repo->id, \HTTP_Request2::METHOD_POST);
         $r->setBody(json_encode((object) array('name' => $file->getFilename(), 'extension' => $file->getExt(), 'content' => $file->isText() ? $file->getContent() : '')));
         $r->send();
     }
 }
 function createSharedChild($newLabel, $newOptions, $parentId, $owner, $uniqueUser)
 {
     $repo = new Repository(0, $newLabel, $this->accessType);
     $newOptions = array_merge($this->options, $newOptions);
     $repo->options = $newOptions;
     $repo->setOwnerData($parentId, $owner, $uniqueUser);
     return $repo;
 }
Example #13
0
 /**
  * test protected _validateData()
  */
 public function testValidateData()
 {
     $sourceClassName = 'Magento_Module_Controller_Index';
     $resultClassName = 'Magento_Module_Controller';
     $repository = new Repository();
     $repository->init($sourceClassName, $resultClassName);
     $this->assertFalse($repository->generate());
 }
Example #14
0
 /**
  * Constructs a commit.
  * If commit data is not given, constructor will fetch them from log.
  *
  * @param Repository $repository    Instance of Repository
  * @param type $commitHash          Commit hash
  * @param array $data               Optional given commit data
  */
 public function __construct(Repository $repository, $commitHash, array $data = [])
 {
     $this->repository = $repository;
     $this->commitHash = $commitHash;
     if (empty($data)) {
         $data = $this->repository->getLog()->getCommitData($commitHash);
     }
     $this->setData($data);
 }
 /**
  * @param array $tags
  * @return \AwsInspector\Model\Collection
  */
 public static function getCollection(array $tags = [])
 {
     $hash = serialize($tags);
     if (!isset(self::$registry[$hash])) {
         $repository = new Repository();
         self::$registry[$hash] = $repository->findEc2InstancesByTags($tags);
     }
     return self::$registry[$hash];
 }
Example #16
0
/**
 * Callback function to validate data
 * @return bool must return true or other hooks don't get called
 */
function validateRepository($editPage, $textBox1, $section, &$hookError)
{
    $ns = $editPage->mTitle->getNamespace();
    if ($ns == NS_REPOSITORY) {
        $repository = new Repository($editPage->mTitle->getText());
        $repository->validate($textBox1, $section, $hookError);
    }
    return true;
}
 /**
  * @test
  */
 public function canRemoveEntity()
 {
     $expectedConditions = array('id' => 1);
     $this->storage->expects($this->once())->method('deleteWhere')->with($expectedConditions)->will($this->returnValue(1));
     $entity = $this->createEntity();
     $entity->setId(1);
     $this->repository->remove($entity);
     $this->assertEquals(null, $entity->getId());
 }
 /**
  * Construction selector
  * @param Repository|null $repository
  */
 public function UserSelection($repository = null, $httpVars = null)
 {
     $this->files = array();
     if (isset($repository) && $repository->hasContentFilter()) {
         $this->contentFilter = $repository->getContentFilter();
     }
     if (isset($httpVars)) {
         $this->initFromHttpVars($httpVars);
     }
 }
Example #19
0
 /**
  * Resolve relations
  *
  * @param array $result
  * @param Repository $repository
  *
  * @return array
  */
 public function resolveRelations(&$results, &$relation, $repository)
 {
     foreach ($results as $result) {
         if (!empty($result[$this->getColumn()])) {
             if (!$repository->isObjectORM($this->getRelation(), $result[$this->getColumn()])) {
                 $relation[$this->getRelation()][$this->getRelationColumn()][$result[$this->getColumn()]] = $result[$this->getColumn()];
             }
         }
     }
 }
Example #20
0
 /**
  * test protected _validateData()
  */
 public function testValidateData()
 {
     $sourceClassName = 'Magento_Module_Controller_Index';
     $resultClassName = 'Magento_Module_Controller';
     $includePathMock = $this->getMockBuilder('Magento\\Framework\\Autoload\\IncludePath')->disableOriginalConstructor()->setMethods(['getFile'])->getMock();
     $includePathMock->expects($this->at(0))->method('getFile')->with($sourceClassName)->will($this->returnValue(true));
     $includePathMock->expects($this->at(1))->method('getFile')->with($resultClassName)->will($this->returnValue(false));
     $repository = new Repository(null, null, null, null, $includePathMock);
     $repository->init($sourceClassName, $resultClassName);
     $this->assertFalse($repository->generate());
 }
 /**
  * Register custom Redis cache driver.
  *
  * @return void
  */
 public function boot()
 {
     Cache::extend('redis', function ($app, $config) {
         $store = new RedisStore($app['redis'], Arr::get($config, 'prefix', $this->app['config']['cache.prefix']), Arr::get($config, 'connection', 'default'));
         $repository = new Repository($store);
         if ($app->bound('Illuminate\\Contracts\\Events\\Dispatcher')) {
             $repository->setEventDispatcher($app['Illuminate\\Contracts\\Events\\Dispatcher']);
         }
         return $repository;
     });
 }
Example #22
0
 public function executeAdd()
 {
     $name = mfwRequest::get('name');
     $project = mfwRequest::get('project');
     if (!$name || !$project) {
         return $this->buildErrorPage("invalid argument (name={$name}, project={$project})", "/pulls/add", 'return');
     }
     $repo = new Repository(array('name' => $name, 'project' => $project));
     $repo->save();
     return $this->redirect("/pulls/index");
 }
Example #23
0
 public function testDeletingDocuments()
 {
     $config = new Config('/tmp/flywheel');
     $repo = new Repository('_pages', $config);
     $id = 'delete_test';
     $name = $id . '_' . sha1($id) . '.json';
     $path = '/tmp/flywheel/_pages/' . $name;
     file_put_contents($path, '');
     $this->assertTrue(is_file($path));
     $repo->delete($id);
     $this->assertFalse(is_file($path));
 }
Example #24
0
 public function testCreateSession()
 {
     $repository = new Repository();
     $ticket = $repository->authenticate("admin", "admin");
     $session = $repository->createSession($ticket);
     $this->assertNotNull($session);
     $this->assertEquals("http://localhost:8080/alfresco/api", $session->repository->connectionUrl);
     $this->assertEquals($ticket, $session->ticket);
     // TODO for now if no ticket is provided a null session is returned
     $session2 = $repository->createSession();
     $this->assertNull($session2);
 }
Example #25
0
 /**
  * @throws Exception
  * @param $request
  * @return void
  */
 public function execute($request)
 {
     $this->form = new RepositoryForm();
     $name = $request->getParameter('name');
     $remote = $request->getParameter('remote');
     // get the propel connection
     $con = Propel::getConnection();
     $con->beginTransaction();
     $message = '';
     try {
         if ($name && $remote) {
             $repositoryPath = Configuration::get('repositories_path');
             $repositoryName = $name;
             $repository = sprintf('%s/%s', $repositoryPath, $repositoryName);
             if (!$this->checkLocalRepository($repository, $remote)) {
                 throw new Exception(sprintf("Existing remote is different from remote you want '%s'", $remote));
             } else {
                 $projectStatus = $this->getProjectStatus($name, $remote);
                 switch ($projectStatus) {
                     case -1:
                         $newProject = new Repository();
                         $newProject->setName($name)->setRemote($remote)->setValue($repositoryName)->save();
                         $message = sprintf("The project has been added successfully");
                         break;
                     case 0:
                         throw new Exception(sprintf("A project already exists and conflicts with project you want to add (name: %s, remote: %s)", $name, $remote));
                         break;
                     default:
                         throw new Exception(sprintf("Project '%s' (remote: %s) already exists", $name, $remote));
                         break;
                 }
                 if (!is_dir($repository)) {
                     $cloneStatus = $this->gitCommand->cloneRepository($remote, $repository);
                     if ($cloneStatus === 0) {
                         $message .= sprintf(" and remote '%s' is correctly cloned in '%s'", $remote, $repository);
                         $this->getUser()->setFlash('notice', $message);
                     } else {
                         $message .= sprintf(" but remote '%s' is not cloned in '%s' [status : %s]", $remote, $repository, $cloneStatus === null ? 'NULL' : $cloneStatus);
                         throw new Exception($message);
                     }
                 }
             }
         } else {
             throw new Exception(sprintf("Parameter name ('%s') or remote ('%s') not found", $name, $remote));
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollBack();
         $this->getUser()->setFlash('error', $e->getMessage());
     }
     $this->redirect("default/repositoryList");
 }
 /**
  * @return AjxpWebdavProvider
  * @throws ezcBaseFileNotFoundException
  */
 protected function getAccessDriver()
 {
     if (!isset($this->accessDriver)) {
         $confDriver = ConfService::getConfStorageImpl();
         $this->accessDriver = ConfService::loadRepositoryDriver();
         if (!$this->accessDriver instanceof AjxpWebdavProvider) {
             throw new ezcBaseFileNotFoundException($this->repository->getUniqueId());
         }
         $wrapperData = $this->accessDriver->detectStreamWrapper(true);
         $this->wrapperClassName = $wrapperData["classname"];
     }
     return $this->accessDriver;
 }
Example #27
0
 public function testBuildInstallFromFile()
 {
     $table = 'someTable';
     $dbMap = $this->createMap();
     $fileMap = $this->createMap();
     $factory = $this->createFactory();
     $install = $this->createInstall();
     $raw = ['stuff'];
     $fileMap->expects($this->once())->method('getInstall')->with($table)->willReturn($raw);
     $factory->expects($this->once())->method('createInstall')->with($this->equalTo($raw))->willReturn($install);
     $repository = new Repository($dbMap, $fileMap, $factory);
     $this->assertEquals($install, $repository->buildInstallFromFile($table));
 }
Example #28
0
 protected function registerEventListeners()
 {
     $registrationModel = $this->config->get('auth::registration_strategy');
     switch ($registrationModel) {
         case 'single_opt_in':
             $this->event->listen('Ipunkt.Auth.*', 'Ipunkt\\Auth\\Listeners\\SingleOptInListener');
             break;
         case 'double_opt_in':
             $this->event->listen('Ipunkt.Auth.*', 'Ipunkt\\Auth\\Listeners\\DoubleOptInListener');
             break;
         default:
     }
 }
Example #29
0
 /**
  * Create a new git repository
  *
  * @param string $repo_path The repository path
  * @param string $source The sources directory
  * @return object A `GitApi\Repository` instance
  */
 public static function create($repo_path, $source = null)
 {
     try {
         $repo = new Repository($repo_path);
         $remote = $repo->getRemoteOriginUrl();
         if ($remote === $source || $remote . '.git' === $source || $remote === $source . '.git') {
             $branch = $repo->getCurrentBranch();
             $repo->pull($remote, $branch);
             return $repo;
         }
     } catch (\Exception $e) {
     }
     return Repository::createNew($repo_path, $source);
 }
 /**
  * @return AjxpWrapperProvider
  * @throws \Sabre\DAV\Exception\NotFound
  */
 public function getAccessDriver()
 {
     if (!isset($this->accessDriver)) {
         //$RID = $this->repository->getId();
         //ConfService::switchRootDir($RID);
         ConfService::getConfStorageImpl();
         $this->accessDriver = ConfService::loadDriverForRepository($this->repository);
         if (!$this->accessDriver instanceof AjxpWrapperProvider) {
             throw new Sabre\DAV\Exception\NotFound($this->repository->getId());
         }
         $this->accessDriver->detectStreamWrapper(true);
     }
     return $this->accessDriver;
 }