installer.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Brice Maron <brice@bmaron.net>
  8. * @author Christian Weiske <cweiske@cweiske.de>
  9. * @author Christopher Schäpers <kondou@ts.unde.re>
  10. * @author Frank Karlitschek <frank@karlitschek.de>
  11. * @author Georg Ehrke <georg@owncloud.com>
  12. * @author Jakob Sack <mail@jakobsack.de>
  13. * @author Joas Schilling <coding@schilljs.com>
  14. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  15. * @author Kamil Domanski <kdomanski@kdemail.net>
  16. * @author Lukas Reschke <lukas@statuscode.ch>
  17. * @author michag86 <micha_g@arcor.de>
  18. * @author Morris Jobke <hey@morrisjobke.de>
  19. * @author Robin Appelman <robin@icewind.nl>
  20. * @author Robin McCorkell <robin@mccorkell.me.uk>
  21. * @author root <root@oc.(none)>
  22. * @author Thomas Müller <thomas.mueller@tmit.eu>
  23. * @author Thomas Tanghus <thomas@tanghus.net>
  24. * @author Vincent Petry <pvince81@owncloud.com>
  25. *
  26. * @license AGPL-3.0
  27. *
  28. * This code is free software: you can redistribute it and/or modify
  29. * it under the terms of the GNU Affero General Public License, version 3,
  30. * as published by the Free Software Foundation.
  31. *
  32. * This program is distributed in the hope that it will be useful,
  33. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. * GNU Affero General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU Affero General Public License, version 3,
  38. * along with this program. If not, see <http://www.gnu.org/licenses/>
  39. *
  40. */
  41. use OC\App\CodeChecker\CodeChecker;
  42. use OC\App\CodeChecker\EmptyCheck;
  43. use OC\App\CodeChecker\PrivateCheck;
  44. use OC\OCSClient;
  45. /**
  46. * This class provides the functionality needed to install, update and remove plugins/apps
  47. */
  48. class OC_Installer{
  49. /**
  50. *
  51. * This function installs an app. All information needed are passed in the
  52. * associative array $data.
  53. * The following keys are required:
  54. * - source: string, can be "path" or "http"
  55. *
  56. * One of the following keys is required:
  57. * - path: path to the file containing the app
  58. * - href: link to the downloadable file containing the app
  59. *
  60. * The following keys are optional:
  61. * - pretend: boolean, if set true the system won't do anything
  62. * - noinstall: boolean, if true appinfo/install.php won't be loaded
  63. * - inactive: boolean, if set true the appconfig/app.sample.php won't be
  64. * renamed
  65. *
  66. * This function works as follows
  67. * -# fetching the file
  68. * -# unzipping it
  69. * -# check the code
  70. * -# installing the database at appinfo/database.xml
  71. * -# including appinfo/install.php
  72. * -# setting the installed version
  73. *
  74. * It is the task of oc_app_install to create the tables and do whatever is
  75. * needed to get the app working.
  76. *
  77. * Installs an app
  78. * @param array $data with all information
  79. * @throws \Exception
  80. * @return integer
  81. */
  82. public static function installApp( $data = array()) {
  83. $l = \OC::$server->getL10N('lib');
  84. list($extractDir, $path) = self::downloadApp($data);
  85. $info = self::checkAppsIntegrity($data, $extractDir, $path);
  86. $appId = OC_App::cleanAppId($info['id']);
  87. $basedir = OC_App::getInstallPath().'/'.$appId;
  88. //check if the destination directory already exists
  89. if(is_dir($basedir)) {
  90. OC_Helper::rmdirr($extractDir);
  91. if($data['source']=='http') {
  92. unlink($path);
  93. }
  94. throw new \Exception($l->t("App directory already exists"));
  95. }
  96. if(!empty($data['pretent'])) {
  97. return false;
  98. }
  99. //copy the app to the correct place
  100. if(@!mkdir($basedir)) {
  101. OC_Helper::rmdirr($extractDir);
  102. if($data['source']=='http') {
  103. unlink($path);
  104. }
  105. throw new \Exception($l->t("Can't create app folder. Please fix permissions. %s", array($basedir)));
  106. }
  107. $extractDir .= '/' . $info['id'];
  108. if(!file_exists($extractDir)) {
  109. OC_Helper::rmdirr($basedir);
  110. throw new \Exception($l->t("Archive does not contain a directory named %s", $info['id']));
  111. }
  112. OC_Helper::copyr($extractDir, $basedir);
  113. //remove temporary files
  114. OC_Helper::rmdirr($extractDir);
  115. //install the database
  116. if(is_file($basedir.'/appinfo/database.xml')) {
  117. if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) {
  118. OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml');
  119. } else {
  120. OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml');
  121. }
  122. }
  123. //run appinfo/install.php
  124. if((!isset($data['noinstall']) or $data['noinstall']==false)) {
  125. self::includeAppScript($basedir . '/appinfo/install.php');
  126. }
  127. //set the installed version
  128. \OC::$server->getAppConfig()->setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id']));
  129. \OC::$server->getAppConfig()->setValue($info['id'], 'enabled', 'no');
  130. //set remote/public handelers
  131. foreach($info['remote'] as $name=>$path) {
  132. OCP\CONFIG::setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
  133. }
  134. foreach($info['public'] as $name=>$path) {
  135. OCP\CONFIG::setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
  136. }
  137. OC_App::setAppTypes($info['id']);
  138. return $info['id'];
  139. }
  140. /**
  141. * @brief checks whether or not an app is installed
  142. * @param string $app app
  143. * @returns bool
  144. *
  145. * Checks whether or not an app is installed, i.e. registered in apps table.
  146. */
  147. public static function isInstalled( $app ) {
  148. return (\OC::$server->getAppConfig()->getValue($app, "installed_version") !== null);
  149. }
  150. /**
  151. * @brief Update an application
  152. * @param array $info
  153. * @param bool $isShipped
  154. * @throws Exception
  155. * @return bool
  156. *
  157. * This function could work like described below, but currently it disables and then
  158. * enables the app again. This does result in an updated app.
  159. *
  160. *
  161. * This function installs an app. All information needed are passed in the
  162. * associative array $info.
  163. * The following keys are required:
  164. * - source: string, can be "path" or "http"
  165. *
  166. * One of the following keys is required:
  167. * - path: path to the file containing the app
  168. * - href: link to the downloadable file containing the app
  169. *
  170. * The following keys are optional:
  171. * - pretend: boolean, if set true the system won't do anything
  172. * - noupgrade: boolean, if true appinfo/upgrade.php won't be loaded
  173. *
  174. * This function works as follows
  175. * -# fetching the file
  176. * -# removing the old files
  177. * -# unzipping new file
  178. * -# including appinfo/upgrade.php
  179. * -# setting the installed version
  180. *
  181. * upgrade.php can determine the current installed version of the app using
  182. * "\OC::$server->getAppConfig()->getValue($appid, 'installed_version')"
  183. */
  184. public static function updateApp($info=array(), $isShipped=false) {
  185. list($extractDir, $path) = self::downloadApp($info);
  186. $info = self::checkAppsIntegrity($info, $extractDir, $path, $isShipped);
  187. $currentDir = OC_App::getAppPath($info['id']);
  188. $basedir = OC_App::getInstallPath();
  189. $basedir .= '/';
  190. $basedir .= $info['id'];
  191. if($currentDir !== false && is_writable($currentDir)) {
  192. $basedir = $currentDir;
  193. }
  194. if(is_dir($basedir)) {
  195. OC_Helper::rmdirr($basedir);
  196. }
  197. $appInExtractDir = $extractDir;
  198. if (substr($extractDir, -1) !== '/') {
  199. $appInExtractDir .= '/';
  200. }
  201. $appInExtractDir .= $info['id'];
  202. OC_Helper::copyr($appInExtractDir, $basedir);
  203. OC_Helper::rmdirr($extractDir);
  204. return OC_App::updateApp($info['id']);
  205. }
  206. /**
  207. * update an app by it's id
  208. *
  209. * @param integer $ocsId
  210. * @return bool
  211. * @throws Exception
  212. */
  213. public static function updateAppByOCSId($ocsId) {
  214. $ocsClient = new OCSClient(
  215. \OC::$server->getHTTPClientService(),
  216. \OC::$server->getConfig(),
  217. \OC::$server->getLogger()
  218. );
  219. $appData = $ocsClient->getApplication($ocsId, \OCP\Util::getVersion());
  220. $download = $ocsClient->getApplicationDownload($ocsId, \OCP\Util::getVersion());
  221. if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
  222. $download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
  223. $info = array(
  224. 'source' => 'http',
  225. 'href' => $download['downloadlink'],
  226. 'appdata' => $appData
  227. );
  228. } else {
  229. throw new \Exception('Could not fetch app info!');
  230. }
  231. return self::updateApp($info);
  232. }
  233. /**
  234. * @param array $data
  235. * @return array
  236. * @throws Exception
  237. */
  238. public static function downloadApp($data = array()) {
  239. $l = \OC::$server->getL10N('lib');
  240. if(!isset($data['source'])) {
  241. throw new \Exception($l->t("No source specified when installing app"));
  242. }
  243. //download the file if necessary
  244. if($data['source']=='http') {
  245. $pathInfo = pathinfo($data['href']);
  246. $extension = isset($pathInfo['extension']) ? '.' . $pathInfo['extension'] : '';
  247. $path = \OC::$server->getTempManager()->getTemporaryFile($extension);
  248. if(!isset($data['href'])) {
  249. throw new \Exception($l->t("No href specified when installing app from http"));
  250. }
  251. $client = \OC::$server->getHTTPClientService()->newClient();
  252. $client->get($data['href'], ['save_to' => $path]);
  253. } else {
  254. if(!isset($data['path'])) {
  255. throw new \Exception($l->t("No path specified when installing app from local file"));
  256. }
  257. $path=$data['path'];
  258. }
  259. //detect the archive type
  260. $mime = \OC::$server->getMimeTypeDetector()->detect($path);
  261. if ($mime !=='application/zip' && $mime !== 'application/x-gzip' && $mime !== 'application/x-bzip2') {
  262. throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
  263. }
  264. //extract the archive in a temporary folder
  265. $extractDir = \OC::$server->getTempManager()->getTemporaryFolder();
  266. OC_Helper::rmdirr($extractDir);
  267. mkdir($extractDir);
  268. if($archive=OC_Archive::open($path)) {
  269. $archive->extract($extractDir);
  270. } else {
  271. OC_Helper::rmdirr($extractDir);
  272. if($data['source']=='http') {
  273. unlink($path);
  274. }
  275. throw new \Exception($l->t("Failed to open archive when installing app"));
  276. }
  277. return array(
  278. $extractDir,
  279. $path
  280. );
  281. }
  282. /**
  283. * check an app's integrity
  284. * @param array $data
  285. * @param string $extractDir
  286. * @param string $path
  287. * @param bool $isShipped
  288. * @return array
  289. * @throws \Exception
  290. */
  291. public static function checkAppsIntegrity($data, $extractDir, $path, $isShipped = false) {
  292. $l = \OC::$server->getL10N('lib');
  293. //load the info.xml file of the app
  294. if(!is_file($extractDir.'/appinfo/info.xml')) {
  295. //try to find it in a subdir
  296. $dh=opendir($extractDir);
  297. if(is_resource($dh)) {
  298. while (($folder = readdir($dh)) !== false) {
  299. if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)) {
  300. if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')) {
  301. $extractDir.='/'.$folder;
  302. }
  303. }
  304. }
  305. }
  306. }
  307. if(!is_file($extractDir.'/appinfo/info.xml')) {
  308. OC_Helper::rmdirr($extractDir);
  309. if($data['source'] === 'http') {
  310. unlink($path);
  311. }
  312. throw new \Exception($l->t("App does not provide an info.xml file"));
  313. }
  314. $info = OC_App::getAppInfo($extractDir.'/appinfo/info.xml', true);
  315. if(!is_array($info)) {
  316. throw new \Exception($l->t('App cannot be installed because appinfo file cannot be read.'));
  317. }
  318. // We can't trust the parsed info.xml file as it may have been tampered
  319. // with by an attacker and thus we need to use the local data to check
  320. // whether the application needs to be signed.
  321. $appId = OC_App::cleanAppId($data['appdata']['id']);
  322. $appBelongingToId = OC_App::getInternalAppIdByOcs($appId);
  323. if(is_string($appBelongingToId)) {
  324. $previouslySigned = \OC::$server->getConfig()->getAppValue($appBelongingToId, 'signed', 'false');
  325. } else {
  326. $appBelongingToId = $info['id'];
  327. $previouslySigned = 'false';
  328. }
  329. if($data['appdata']['level'] === OC_App::officialApp || $previouslySigned === 'true') {
  330. \OC::$server->getConfig()->setAppValue($appBelongingToId, 'signed', 'true');
  331. $integrityResult = \OC::$server->getIntegrityCodeChecker()->verifyAppSignature(
  332. $appBelongingToId,
  333. $extractDir
  334. );
  335. if($integrityResult !== []) {
  336. $e = new \Exception(
  337. $l->t(
  338. 'Signature could not get checked. Please contact the app developer and check your admin screen.'
  339. )
  340. );
  341. throw $e;
  342. }
  343. }
  344. // check the code for not allowed calls
  345. if(!$isShipped && !OC_Installer::checkCode($extractDir)) {
  346. OC_Helper::rmdirr($extractDir);
  347. throw new \Exception($l->t("App can't be installed because of not allowed code in the App"));
  348. }
  349. // check if the app is compatible with this version of ownCloud
  350. if(!OC_App::isAppCompatible(\OCP\Util::getVersion(), $info)) {
  351. OC_Helper::rmdirr($extractDir);
  352. throw new \Exception($l->t("App can't be installed because it is not compatible with this version of Nextcloud"));
  353. }
  354. // check if shipped tag is set which is only allowed for apps that are shipped with ownCloud
  355. if(!$isShipped && isset($info['shipped']) && ($info['shipped']=='true')) {
  356. OC_Helper::rmdirr($extractDir);
  357. throw new \Exception($l->t("App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps"));
  358. }
  359. // check if the ocs version is the same as the version in info.xml/version
  360. $versionFile= $extractDir.'/appinfo/version';
  361. if(is_file($versionFile)) {
  362. $version = trim(file_get_contents($versionFile));
  363. }else{
  364. $version = trim($info['version']);
  365. }
  366. if(isset($data['appdata']['version']) && $version<>trim($data['appdata']['version'])) {
  367. OC_Helper::rmdirr($extractDir);
  368. throw new \Exception($l->t("App can't be installed because the version in info.xml/version is not the same as the version reported from the app store"));
  369. }
  370. return $info;
  371. }
  372. /**
  373. * Check if an update for the app is available
  374. * @param string $app
  375. * @return string|false false or the version number of the update
  376. *
  377. * The function will check if an update for a version is available
  378. */
  379. public static function isUpdateAvailable( $app ) {
  380. static $isInstanceReadyForUpdates = null;
  381. if ($isInstanceReadyForUpdates === null) {
  382. $installPath = OC_App::getInstallPath();
  383. if ($installPath === false || $installPath === null) {
  384. $isInstanceReadyForUpdates = false;
  385. } else {
  386. $isInstanceReadyForUpdates = true;
  387. }
  388. }
  389. if ($isInstanceReadyForUpdates === false) {
  390. return false;
  391. }
  392. $ocsid=\OC::$server->getAppConfig()->getValue( $app, 'ocsid', '');
  393. if($ocsid<>'') {
  394. $ocsClient = new OCSClient(
  395. \OC::$server->getHTTPClientService(),
  396. \OC::$server->getConfig(),
  397. \OC::$server->getLogger()
  398. );
  399. $ocsdata = $ocsClient->getApplication($ocsid, \OCP\Util::getVersion());
  400. $ocsversion= (string) $ocsdata['version'];
  401. $currentversion=OC_App::getAppVersion($app);
  402. if (version_compare($ocsversion, $currentversion, '>')) {
  403. return($ocsversion);
  404. }else{
  405. return false;
  406. }
  407. }else{
  408. return false;
  409. }
  410. }
  411. /**
  412. * Check if app is already downloaded
  413. * @param string $name name of the application to remove
  414. * @return boolean
  415. *
  416. * The function will check if the app is already downloaded in the apps repository
  417. */
  418. public static function isDownloaded( $name ) {
  419. foreach(OC::$APPSROOTS as $dir) {
  420. $dirToTest = $dir['path'];
  421. $dirToTest .= '/';
  422. $dirToTest .= $name;
  423. $dirToTest .= '/';
  424. if (is_dir($dirToTest)) {
  425. return true;
  426. }
  427. }
  428. return false;
  429. }
  430. /**
  431. * Removes an app
  432. * @param string $name name of the application to remove
  433. * @param array $options options
  434. * @return boolean
  435. *
  436. * This function removes an app. $options is an associative array. The
  437. * following keys are optional:ja
  438. * - keeppreferences: boolean, if true the user preferences won't be deleted
  439. * - keepappconfig: boolean, if true the config will be kept
  440. * - keeptables: boolean, if true the database will be kept
  441. * - keepfiles: boolean, if true the user files will be kept
  442. *
  443. * This function works as follows
  444. * -# including appinfo/remove.php
  445. * -# removing the files
  446. *
  447. * The function will not delete preferences, tables and the configuration,
  448. * this has to be done by the function oc_app_uninstall().
  449. */
  450. public static function removeApp( $name, $options = array()) {
  451. if(isset($options['keeppreferences']) and $options['keeppreferences']==false ) {
  452. // todo
  453. // remove preferences
  454. }
  455. if(isset($options['keepappconfig']) and $options['keepappconfig']==false ) {
  456. // todo
  457. // remove app config
  458. }
  459. if(isset($options['keeptables']) and $options['keeptables']==false ) {
  460. // todo
  461. // remove app database tables
  462. }
  463. if(isset($options['keepfiles']) and $options['keepfiles']==false ) {
  464. // todo
  465. // remove user files
  466. }
  467. if(OC_Installer::isDownloaded( $name )) {
  468. $appdir=OC_App::getInstallPath().'/'.$name;
  469. OC_Helper::rmdirr($appdir);
  470. return true;
  471. }else{
  472. \OCP\Util::writeLog('core', 'can\'t remove app '.$name.'. It is not installed.', \OCP\Util::ERROR);
  473. return false;
  474. }
  475. }
  476. /**
  477. * Installs shipped apps
  478. *
  479. * This function installs all apps found in the 'apps' directory that should be enabled by default;
  480. * @param bool $softErrors When updating we ignore errors and simply log them, better to have a
  481. * working ownCloud at the end instead of an aborted update.
  482. * @return array Array of error messages (appid => Exception)
  483. */
  484. public static function installShippedApps($softErrors = false) {
  485. $errors = [];
  486. foreach(OC::$APPSROOTS as $app_dir) {
  487. if($dir = opendir( $app_dir['path'] )) {
  488. while( false !== ( $filename = readdir( $dir ))) {
  489. if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) {
  490. if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
  491. if(!OC_Installer::isInstalled($filename)) {
  492. $info=OC_App::getAppInfo($filename);
  493. $enabled = isset($info['default_enable']);
  494. if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
  495. && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
  496. if ($softErrors) {
  497. try {
  498. OC_Installer::installShippedApp($filename);
  499. } catch (\OC\HintException $e) {
  500. if ($e->getPrevious() instanceof \Doctrine\DBAL\Exception\TableExistsException) {
  501. $errors[$filename] = $e;
  502. continue;
  503. }
  504. throw $e;
  505. }
  506. } else {
  507. OC_Installer::installShippedApp($filename);
  508. }
  509. \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
  510. }
  511. }
  512. }
  513. }
  514. }
  515. closedir( $dir );
  516. }
  517. }
  518. return $errors;
  519. }
  520. /**
  521. * install an app already placed in the app folder
  522. * @param string $app id of the app to install
  523. * @return integer
  524. */
  525. public static function installShippedApp($app) {
  526. //install the database
  527. $appPath = OC_App::getAppPath($app);
  528. if(is_file("$appPath/appinfo/database.xml")) {
  529. try {
  530. OC_DB::createDbFromStructure("$appPath/appinfo/database.xml");
  531. } catch (\Doctrine\DBAL\Exception\TableExistsException $e) {
  532. throw new \OC\HintException(
  533. 'Failed to enable app ' . $app,
  534. 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.',
  535. 0, $e
  536. );
  537. }
  538. }
  539. //run appinfo/install.php
  540. \OC::$loader->addValidRoot($appPath);
  541. self::includeAppScript("$appPath/appinfo/install.php");
  542. $info = OC_App::getAppInfo($app);
  543. if (is_null($info)) {
  544. return false;
  545. }
  546. $config = \OC::$server->getConfig();
  547. $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app));
  548. if (array_key_exists('ocsid', $info)) {
  549. $config->setAppValue($app, 'ocsid', $info['ocsid']);
  550. }
  551. //set remote/public handlers
  552. foreach($info['remote'] as $name=>$path) {
  553. $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path);
  554. }
  555. foreach($info['public'] as $name=>$path) {
  556. $config->setAppValue('core', 'public_'.$name, $app.'/'.$path);
  557. }
  558. OC_App::setAppTypes($info['id']);
  559. return $info['id'];
  560. }
  561. /**
  562. * check the code of an app with some static code checks
  563. * @param string $folder the folder of the app to check
  564. * @return boolean true for app is o.k. and false for app is not o.k.
  565. */
  566. public static function checkCode($folder) {
  567. // is the code checker enabled?
  568. if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) {
  569. return true;
  570. }
  571. $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck()));
  572. $errors = $codeChecker->analyseFolder($folder);
  573. return empty($errors);
  574. }
  575. /**
  576. * @param $basedir
  577. */
  578. private static function includeAppScript($script) {
  579. if ( file_exists($script) ){
  580. include $script;
  581. }
  582. }
  583. }