Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AppManager::getAppPath #29871

Merged
merged 2 commits into from
Jan 8, 2018
Merged

Implement AppManager::getAppPath #29871

merged 2 commits into from
Jan 8, 2018

Conversation

VicDeo
Copy link
Member

@VicDeo VicDeo commented Dec 15, 2017

Description

  • Allows to get the app path and app web path
  • Kill legacy code that does the same. OC_App::getAppPath and OC_App::getAppWebPath are cut down to work via AppManager implementation
  • It is possible to use some AppManager methods without Db connection now (e.g. when OC is not installed)

Related Issue

#25336

Motivation and Context

  • public API enhancement
  • unit testing is possible now
  • killing old crap

How Has This Been Tested?

\OC::$server->getAppManager()->getAppPath('customgroups');
\OC::$server->getAppManager()->getAppWebPath('customgroups');

where 'customgroups' is your favorite app. In a various configs including multiple app directories.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@VicDeo VicDeo self-assigned this Dec 15, 2017
@VicDeo VicDeo added this to the development milestone Dec 15, 2017
@VicDeo VicDeo force-pushed the implement-25336 branch 2 times, most recently from 42c6a97 to 44b9f2a Compare December 15, 2017 18:27
}

/**
* Get the directory for the given app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method description needs an update. (copy-pasted from method above but not yet modified)

@VicDeo VicDeo force-pushed the implement-25336 branch 2 times, most recently from 24bccd0 to 1da9920 Compare December 19, 2017 21:08
@codecov
Copy link

codecov bot commented Dec 20, 2017

Codecov Report

Merging #29871 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #29871      +/-   ##
============================================
- Coverage     58.21%   58.19%   -0.03%     
+ Complexity    18512    18458      -54     
============================================
  Files          1093     1092       -1     
  Lines         63693    63619      -74     
============================================
- Hits          37082    37025      -57     
+ Misses        26611    26594      -17
Impacted Files Coverage Δ Complexity Δ
drone/src/apps/dav/lib/Connector/Sabre/File.php 83.33% <0%> (-1.15%) 103% <0%> (-36%)
drone/src/lib/private/Server.php 82.47% <0%> (-0.24%) 129% <0%> (+1%)
drone/src/lib/private/Files/View.php 84.61% <0%> (-0.18%) 370% <0%> (-6%)
drone/src/lib/private/legacy/app.php 59.11% <0%> (-0.14%) 184% <0%> (-14%)
drone/src/lib/private/User/User.php 82.82% <0%> (-0.11%) 63% <0%> (ø)
drone/src/lib/private/User/Session.php 62.13% <0%> (-0.04%) 124% <0%> (ø)
drone/src/lib/private/SystemConfig.php 44.44% <0%> (ø) 14% <0%> (ø) ⬇️
...ate/Files/External/Service/UserStoragesService.php 100% <0%> (ø) 11% <0%> (ø) ⬇️
drone/src/lib/private/Files/Filesystem.php 70.03% <0%> (ø) 127% <0%> (ø) ⬇️
.../private/Files/External/Auth/Password/Password.php 0% <0%> (ø) 1% <0%> (ø) ⬇️
... and 60 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cce5ef...131e688. Read the comment docs.

@VicDeo VicDeo changed the title [WIP] Implement getAppPath Implement getAppPath Dec 20, 2017
@VicDeo VicDeo requested a review from PVince81 December 21, 2017 10:14
Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good to me.

Feel free to ignore the comments if they apply on old code you just moved to another location. If you do fix them, let's make sure there is no risk of regression.

if (trim($appId) === '') {
return false;
}
if (($appRoot = $this->findAppInDirectories($appId)) != false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!== false ?

same below

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to leave it if it's just copy-pasted bad old code

* @param string $appId
* @return false|string[]
*/
protected function findAppInDirectories($appId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double space between protected and function

$versionToLoad = [];
foreach ($possibleAppRoots as $possibleAppRoot) {
$version = $this->getAppVersionByPath($possibleAppRoot['path'] . '/' . $appId);
if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty() , fortunately we don't have a version "0" which would qualify as true for empty("0")

Copy link
Member Author

@VicDeo VicDeo Dec 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG! an evil app-developer can write an app that will never be loaded :)
Just kidding. this piece of sh code chooses the most recent app version from the appRoots.
$versionToLoad is an array containing properties ['path', 'url', 'version'] of the winner so empty is valid in this context.
empty($versionToLoad) means there is no winner currently.

@VicDeo
Copy link
Member Author

VicDeo commented Dec 26, 2017

@PVince81 I changed comparison to be strict and removed double space.
findAppInDirectories always returns either false or non-empty array so these changes are regression-safe. (going to retest)

@VicDeo VicDeo changed the title Implement getAppPath Implement AppManager::getAppPath Dec 26, 2017
@@ -166,4 +166,26 @@ public function readAppPackage($path);
* @since 10.0.3
*/
public function canInstall();

/**
* Get the directory for the given app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind adding a detail whether this is an absolute path or relative path (and relative to what)

* @return string|false
* @since 10.0.5
*/
public function getAppWebPath($appId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's a web path ? maybe an example in PHPDoc will help clarify

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the two clarifications (optional)

@VicDeo
Copy link
Member Author

VicDeo commented Jan 8, 2018

@PVince81 thanks, will do

//Just for my reference as both comments are related to
apps_paths content https://github.com/owncloud/core/blob/master/config/config.sample.php#L715

@VicDeo
Copy link
Member Author

VicDeo commented Jan 8, 2018

@PVince81 PHPDocs updated

@PVince81
Copy link
Contributor

PVince81 commented Jan 8, 2018

tests were green before, only PHP Doc changes, insta-merge

@PVince81 PVince81 merged commit 9dbcc9a into master Jan 8, 2018
@PVince81 PVince81 deleted the implement-25336 branch January 8, 2018 13:04
@PVince81
Copy link
Contributor

PVince81 commented Jan 8, 2018

@VicDeo please backport to stable10

@VicDeo
Copy link
Member Author

VicDeo commented Jan 8, 2018

Stable10: #30041

@lock
Copy link

lock bot commented Aug 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants