local.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @copyright Copyright (c) 2015, ownCloud, Inc.
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Files_Sharing\API;
  27. use OC\HintException;
  28. class Local {
  29. /**
  30. * get all shares
  31. *
  32. * @param array $params option 'file' to limit the result to a specific file/folder
  33. * @return \OC_OCS_Result share information
  34. */
  35. public static function getAllShares($params) {
  36. if (isset($_GET['shared_with_me']) && $_GET['shared_with_me'] !== 'false') {
  37. return self::getFilesSharedWithMe();
  38. }
  39. // if a file is specified, get the share for this file
  40. if (isset($_GET['path'])) {
  41. if ( isset($_GET['reshares']) && $_GET['reshares'] !== 'false' ) {
  42. $reshares = true;
  43. } else {
  44. $reshares = false;
  45. }
  46. if (isset($_GET['subfiles']) && $_GET['subfiles'] !== 'false') {
  47. return self::getSharesFromFolder($_GET['path']);
  48. }
  49. return self::collectShares(self::getFileId($_GET['path']),
  50. self::getItemType($_GET['path']),
  51. false,
  52. $_GET['path'],
  53. $reshares);
  54. }
  55. $shares = \OCP\Share::getItemShared('file', null);
  56. if ($shares === false) {
  57. return new \OC_OCS_Result(null, 404, 'could not get shares');
  58. } else {
  59. foreach ($shares as &$share) {
  60. if ($share['item_type'] === 'file' && isset($share['path'])) {
  61. $share['mimetype'] = \OC_Helper::getFileNameMimeType($share['path']);
  62. if (\OC::$server->getPreviewManager()->isMimeSupported($share['mimetype'])) {
  63. $share['isPreviewAvailable'] = true;
  64. }
  65. }
  66. if (!is_null($share['token'])) {
  67. $share['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share['token']]);
  68. }
  69. }
  70. return new \OC_OCS_Result($shares);
  71. }
  72. }
  73. /**
  74. * get share information for a given share
  75. *
  76. * @param array $params which contains a 'id'
  77. * @return \OC_OCS_Result share information
  78. */
  79. public static function getShare($params) {
  80. $s = self::getShareFromId($params['id']);
  81. return self::collectShares($s['file_source'], $s['item_type'], true, null, false, (int)$params['id']);
  82. }
  83. /**
  84. * collect all share information, either of a specific share or all
  85. * shares for a given path
  86. *
  87. * @param string $itemSource
  88. * @param string $itemType
  89. * @param bool $getSpecificShare
  90. * @param string $path
  91. * @param bool $reshares
  92. * @param int $id
  93. *
  94. * @return \OC_OCS_Result
  95. */
  96. private static function collectShares($itemSource, $itemType, $getSpecificShare = false, $path = null, $reshares = false, $id = null) {
  97. if ($itemSource !== null) {
  98. $shares = \OCP\Share::getItemShared($itemType, $itemSource);
  99. $receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $itemSource);
  100. // if a specific share was specified only return this one
  101. if ($getSpecificShare === true) {
  102. foreach ($shares as $share) {
  103. if ($share['id'] === $id) {
  104. $shares = array('element' => $share);
  105. break;
  106. }
  107. }
  108. } else {
  109. foreach ($shares as $key => $share) {
  110. $shares[$key]['path'] = $path;
  111. }
  112. }
  113. // include also reshares in the lists. This means that the result
  114. // will contain every user with access to the file.
  115. if ($reshares === true) {
  116. $shares = self::addReshares($shares, $itemSource);
  117. }
  118. if ($receivedFrom) {
  119. foreach ($shares as $key => $share) {
  120. $shares[$key]['received_from'] = $receivedFrom['uid_owner'];
  121. $shares[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
  122. }
  123. }
  124. } else {
  125. $shares = null;
  126. }
  127. if ($shares === null || empty($shares)) {
  128. return new \OC_OCS_Result(null, 404, 'share doesn\'t exist');
  129. } else {
  130. foreach ($shares as &$share) {
  131. if (!is_null($share['token'])) {
  132. $share['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share['token']]);
  133. }
  134. }
  135. return new \OC_OCS_Result($shares);
  136. }
  137. }
  138. /**
  139. * add reshares to a array of shares
  140. * @param array $shares array of shares
  141. * @param int $itemSource item source ID
  142. * @return array new shares array which includes reshares
  143. */
  144. private static function addReshares($shares, $itemSource) {
  145. // if there are no shares than there are also no reshares
  146. $firstShare = reset($shares);
  147. if ($firstShare) {
  148. $path = $firstShare['path'];
  149. } else {
  150. return $shares;
  151. }
  152. $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path` , `*PREFIX*share`.`permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`, `mail_send`';
  153. $getReshares = \OCP\DB::prepare('SELECT ' . $select . ' FROM `*PREFIX*share` INNER JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `*PREFIX*share`.`file_source` = ? AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\') AND `uid_owner` != ?');
  154. $reshares = $getReshares->execute(array($itemSource, \OCP\User::getUser()))->fetchAll();
  155. foreach ($reshares as $key => $reshare) {
  156. if (isset($reshare['share_with']) && $reshare['share_with'] !== '') {
  157. $reshares[$key]['share_with_displayname'] = \OCP\User::getDisplayName($reshare['share_with']);
  158. }
  159. // add correct path to the result
  160. $reshares[$key]['path'] = $path;
  161. }
  162. return array_merge($shares, $reshares);
  163. }
  164. /**
  165. * get share from all files in a given folder (non-recursive)
  166. * @param string $path
  167. * @return \OC_OCS_Result
  168. */
  169. private static function getSharesFromFolder($path) {
  170. $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
  171. if(!$view->is_dir($path)) {
  172. return new \OC_OCS_Result(null, 400, "not a directory");
  173. }
  174. $content = $view->getDirectoryContent($path);
  175. $result = array();
  176. foreach ($content as $file) {
  177. // workaround because folders are named 'dir' in this context
  178. $itemType = $file['type'] === 'file' ? 'file' : 'folder';
  179. $share = \OCP\Share::getItemShared($itemType, $file['fileid']);
  180. if($share) {
  181. $receivedFrom = \OCP\Share::getItemSharedWithBySource($itemType, $file['fileid']);
  182. reset($share);
  183. $key = key($share);
  184. if ($receivedFrom) {
  185. $share[$key]['received_from'] = $receivedFrom['uid_owner'];
  186. $share[$key]['received_from_displayname'] = \OCP\User::getDisplayName($receivedFrom['uid_owner']);
  187. }
  188. $result = array_merge($result, $share);
  189. }
  190. }
  191. return new \OC_OCS_Result($result);
  192. }
  193. /**
  194. * get files shared with the user
  195. * @return \OC_OCS_Result
  196. */
  197. private static function getFilesSharedWithMe() {
  198. try {
  199. $shares = \OCP\Share::getItemsSharedWith('file');
  200. foreach ($shares as &$share) {
  201. if ($share['item_type'] === 'file') {
  202. $share['mimetype'] = \OC_Helper::getFileNameMimeType($share['file_target']);
  203. if (\OC::$server->getPreviewManager()->isMimeSupported($share['mimetype'])) {
  204. $share['isPreviewAvailable'] = true;
  205. }
  206. }
  207. }
  208. $result = new \OC_OCS_Result($shares);
  209. } catch (\Exception $e) {
  210. $result = new \OC_OCS_Result(null, 403, $e->getMessage());
  211. }
  212. return $result;
  213. }
  214. /**
  215. * create a new share
  216. * @param array $params
  217. * @return \OC_OCS_Result
  218. */
  219. public static function createShare($params) {
  220. $path = isset($_POST['path']) ? $_POST['path'] : null;
  221. if($path === null) {
  222. return new \OC_OCS_Result(null, 400, "please specify a file or folder path");
  223. }
  224. $itemSource = self::getFileId($path);
  225. $itemSourceName = $itemSource;
  226. $itemType = self::getItemType($path);
  227. $expirationDate = null;
  228. if($itemSource === null) {
  229. return new \OC_OCS_Result(null, 404, "wrong path, file/folder doesn't exist.");
  230. }
  231. $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null;
  232. $shareType = isset($_POST['shareType']) ? (int)$_POST['shareType'] : null;
  233. switch($shareType) {
  234. case \OCP\Share::SHARE_TYPE_REMOTE:
  235. $shareWith = rtrim($shareWith, '/');
  236. $itemSourceName = basename($path);
  237. case \OCP\Share::SHARE_TYPE_USER:
  238. case \OCP\Share::SHARE_TYPE_GROUP:
  239. $permissions = isset($_POST['permissions']) ? (int)$_POST['permissions'] : 31;
  240. break;
  241. case \OCP\Share::SHARE_TYPE_LINK:
  242. //allow password protection
  243. $shareWith = isset($_POST['password']) ? $_POST['password'] : null;
  244. //check public link share
  245. $publicUploadEnabled = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes');
  246. if(isset($_POST['publicUpload']) && $publicUploadEnabled !== 'yes') {
  247. return new \OC_OCS_Result(null, 403, "public upload disabled by the administrator");
  248. }
  249. $publicUpload = isset($_POST['publicUpload']) ? $_POST['publicUpload'] : 'false';
  250. // read, create, update (7) if public upload is enabled or
  251. // read (1) if public upload is disabled
  252. $permissions = $publicUpload === 'true' ? 7 : 1;
  253. // Get the expiration date
  254. try {
  255. $expirationDate = isset($_POST['expireDate']) ? self::parseDate($_POST['expireDate']) : null;
  256. } catch (\Exception $e) {
  257. return new \OC_OCS_Result(null, 404, 'Invalid Date. Format must be YYYY-MM-DD.');
  258. }
  259. break;
  260. default:
  261. return new \OC_OCS_Result(null, 400, "unknown share type");
  262. }
  263. if (($permissions & \OCP\Constants::PERMISSION_READ) === 0) {
  264. return new \OC_OCS_Result(null, 400, 'invalid permissions');
  265. }
  266. try {
  267. $token = \OCP\Share::shareItem(
  268. $itemType,
  269. $itemSource,
  270. $shareType,
  271. $shareWith,
  272. $permissions,
  273. $itemSourceName,
  274. $expirationDate
  275. );
  276. } catch (HintException $e) {
  277. if ($e->getCode() === 0) {
  278. return new \OC_OCS_Result(null, 400, $e->getHint());
  279. } else {
  280. return new \OC_OCS_Result(null, $e->getCode(), $e->getHint());
  281. }
  282. } catch (\Exception $e) {
  283. return new \OC_OCS_Result(null, 403, $e->getMessage());
  284. }
  285. if ($token) {
  286. $data = array();
  287. $data['id'] = 'unknown';
  288. $shares = \OCP\Share::getItemShared($itemType, $itemSource);
  289. if(is_string($token)) { //public link share
  290. foreach ($shares as $share) {
  291. if ($share['token'] === $token) {
  292. $data['id'] = $share['id'];
  293. break;
  294. }
  295. }
  296. $data['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $token]);
  297. $data['token'] = $token;
  298. } else {
  299. foreach ($shares as $share) {
  300. if ($share['share_with'] === $shareWith && $share['share_type'] === $shareType) {
  301. $data['id'] = $share['id'];
  302. break;
  303. }
  304. }
  305. }
  306. $data['permissions'] = $share['permissions'];
  307. $data['expiration'] = $share['expiration'];
  308. return new \OC_OCS_Result($data);
  309. } else {
  310. return new \OC_OCS_Result(null, 404, "couldn't share file");
  311. }
  312. }
  313. /**
  314. * update shares, e.g. password, permissions, etc
  315. * @param array $params shareId 'id' and the parameter we want to update
  316. * currently supported: permissions, password, publicUpload
  317. * @return \OC_OCS_Result
  318. */
  319. public static function updateShare($params) {
  320. $share = self::getShareFromId($params['id']);
  321. if(!isset($share['file_source'])) {
  322. return new \OC_OCS_Result(null, 404, "wrong share Id, share doesn't exist.");
  323. }
  324. try {
  325. if(isset($params['_put']['permissions'])) {
  326. return self::updatePermissions($share, $params);
  327. } elseif (isset($params['_put']['password'])) {
  328. return self::updatePassword($params['id'], (int)$share['share_type'], $params['_put']['password']);
  329. } elseif (isset($params['_put']['publicUpload'])) {
  330. return self::updatePublicUpload($share, $params);
  331. } elseif (isset($params['_put']['expireDate'])) {
  332. return self::updateExpireDate($share, $params);
  333. }
  334. } catch (\Exception $e) {
  335. return new \OC_OCS_Result(null, 400, $e->getMessage());
  336. }
  337. return new \OC_OCS_Result(null, 400, "Wrong or no update parameter given");
  338. }
  339. /**
  340. * update permissions for a share
  341. * @param array $share information about the share
  342. * @param array $params contains 'permissions'
  343. * @return \OC_OCS_Result
  344. */
  345. private static function updatePermissions($share, $params) {
  346. $itemSource = $share['item_source'];
  347. $itemType = $share['item_type'];
  348. $shareWith = $share['share_with'];
  349. $shareType = $share['share_type'];
  350. $permissions = isset($params['_put']['permissions']) ? (int)$params['_put']['permissions'] : null;
  351. $publicUploadStatus = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes');
  352. $publicUploadEnabled = ($publicUploadStatus === 'yes') ? true : false;
  353. // only change permissions for public shares if public upload is enabled
  354. // and we want to set permissions to 1 (read only) or 7 (allow upload)
  355. if ( (int)$shareType === \OCP\Share::SHARE_TYPE_LINK ) {
  356. if ($publicUploadEnabled === false || ($permissions !== 7 && $permissions !== 1)) {
  357. return new \OC_OCS_Result(null, 400, "can't change permission for public link share");
  358. }
  359. }
  360. if (($permissions & \OCP\Constants::PERMISSION_READ) === 0) {
  361. return new \OC_OCS_Result(null, 400, 'invalid permissions');
  362. }
  363. try {
  364. $return = \OCP\Share::setPermissions(
  365. $itemType,
  366. $itemSource,
  367. $shareType,
  368. $shareWith,
  369. $permissions
  370. );
  371. } catch (\Exception $e) {
  372. return new \OC_OCS_Result(null, 404, $e->getMessage());
  373. }
  374. if ($return) {
  375. return new \OC_OCS_Result();
  376. } else {
  377. return new \OC_OCS_Result(null, 404, "couldn't set permissions");
  378. }
  379. }
  380. /**
  381. * enable/disable public upload
  382. * @param array $share information about the share
  383. * @param array $params contains 'publicUpload' which can be 'yes' or 'no'
  384. * @return \OC_OCS_Result
  385. */
  386. private static function updatePublicUpload($share, $params) {
  387. $publicUploadEnabled = \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_public_upload', 'yes');
  388. if($publicUploadEnabled !== 'yes') {
  389. return new \OC_OCS_Result(null, 403, "public upload disabled by the administrator");
  390. }
  391. if ($share['item_type'] !== 'folder' ||
  392. (int)$share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK ) {
  393. return new \OC_OCS_Result(null, 400, "public upload is only possible for public shared folders");
  394. }
  395. // read, create, update (7) if public upload is enabled or
  396. // read (1) if public upload is disabled
  397. $params['_put']['permissions'] = $params['_put']['publicUpload'] === 'true' ? 7 : 1;
  398. return self::updatePermissions($share, $params);
  399. }
  400. /**
  401. * set expire date for public link share
  402. * @param array $share information about the share
  403. * @param array $params contains 'expireDate' which needs to be a well formated date string, e.g DD-MM-YYYY
  404. * @return \OC_OCS_Result
  405. */
  406. private static function updateExpireDate($share, $params) {
  407. // only public links can have a expire date
  408. if ((int)$share['share_type'] !== \OCP\Share::SHARE_TYPE_LINK ) {
  409. return new \OC_OCS_Result(null, 400, "expire date only exists for public link shares");
  410. }
  411. try {
  412. $expireDateSet = \OCP\Share::setExpirationDate($share['item_type'], $share['item_source'], $params['_put']['expireDate'], (int)$share['stime']);
  413. $result = ($expireDateSet) ? new \OC_OCS_Result() : new \OC_OCS_Result(null, 404, "couldn't set expire date");
  414. } catch (\Exception $e) {
  415. $result = new \OC_OCS_Result(null, 404, $e->getMessage());
  416. }
  417. return $result;
  418. }
  419. /**
  420. * update password for public link share
  421. * @param int $shareId
  422. * @param int $shareType
  423. * @param string $password
  424. * @return \OC_OCS_Result
  425. */
  426. private static function updatePassword($shareId, $shareType, $password) {
  427. if($shareType !== \OCP\Share::SHARE_TYPE_LINK) {
  428. return new \OC_OCS_Result(null, 400, "password protection is only supported for public shares");
  429. }
  430. if($password === '') {
  431. $password = null;
  432. }
  433. try {
  434. $result = \OCP\Share::setPassword($shareId, $password);
  435. } catch (\Exception $e) {
  436. return new \OC_OCS_Result(null, 403, $e->getMessage());
  437. }
  438. if($result) {
  439. return new \OC_OCS_Result();
  440. }
  441. return new \OC_OCS_Result(null, 404, "couldn't set password");
  442. }
  443. /**
  444. * unshare a file/folder
  445. * @param array $params contains the shareID 'id' which should be unshared
  446. * @return \OC_OCS_Result
  447. */
  448. public static function deleteShare($params) {
  449. $share = self::getShareFromId($params['id']);
  450. $fileSource = isset($share['file_source']) ? $share['file_source'] : null;
  451. $itemType = isset($share['item_type']) ? $share['item_type'] : null;;
  452. if($fileSource === null) {
  453. return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
  454. }
  455. $shareWith = isset($share['share_with']) ? $share['share_with'] : null;
  456. $shareType = isset($share['share_type']) ? (int)$share['share_type'] : null;
  457. if( $shareType === \OCP\Share::SHARE_TYPE_LINK) {
  458. $shareWith = null;
  459. }
  460. try {
  461. $return = \OCP\Share::unshare(
  462. $itemType,
  463. $fileSource,
  464. $shareType,
  465. $shareWith);
  466. } catch (\Exception $e) {
  467. return new \OC_OCS_Result(null, 404, $e->getMessage());
  468. }
  469. if ($return) {
  470. return new \OC_OCS_Result();
  471. } else {
  472. $msg = "Unshare Failed";
  473. return new \OC_OCS_Result(null, 404, $msg);
  474. }
  475. }
  476. /**
  477. * Make sure that the passed date is valid ISO 8601
  478. * So YYYY-MM-DD
  479. * If not throw an exception
  480. *
  481. * @param string $expireDate
  482. *
  483. * @throws \Exception
  484. * @return \DateTime
  485. */
  486. private static function parseDate($expireDate) {
  487. if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $expireDate) === 0) {
  488. throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
  489. }
  490. $date = new \DateTime($expireDate);
  491. if ($date === false) {
  492. throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
  493. }
  494. return $date;
  495. }
  496. /**
  497. * get file ID from a given path
  498. * @param string $path
  499. * @return string fileID or null
  500. */
  501. private static function getFileId($path) {
  502. $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
  503. $fileId = null;
  504. $fileInfo = $view->getFileInfo($path);
  505. if ($fileInfo) {
  506. $fileId = $fileInfo['fileid'];
  507. }
  508. return $fileId;
  509. }
  510. /**
  511. * get itemType
  512. * @param string $path
  513. * @return string type 'file', 'folder' or null of file/folder doesn't exists
  514. */
  515. private static function getItemType($path) {
  516. $view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
  517. $itemType = null;
  518. if ($view->is_dir($path)) {
  519. $itemType = "folder";
  520. } elseif ($view->is_file($path)) {
  521. $itemType = "file";
  522. }
  523. return $itemType;
  524. }
  525. /**
  526. * get some information from a given share
  527. * @param int $shareID
  528. * @return array with: item_source, share_type, share_with, item_type, permissions
  529. */
  530. private static function getShareFromId($shareID) {
  531. $sql = 'SELECT `file_source`, `item_source`, `share_type`, `share_with`, `item_type`, `permissions`, `stime` FROM `*PREFIX*share` WHERE `id` = ?';
  532. $args = array($shareID);
  533. $query = \OCP\DB::prepare($sql);
  534. $result = $query->execute($args);
  535. if (\OCP\DB::isError($result)) {
  536. \OCP\Util::writeLog('files_sharing', \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
  537. return null;
  538. }
  539. if ($share = $result->fetchRow()) {
  540. return $share;
  541. }
  542. return null;
  543. }
  544. }