3838use OC \Share20 \Exception \BackendError ;
3939use OC \Share20 \Exception \InvalidShare ;
4040use OC \Share20 \Exception \ProviderException ;
41+ use OCP \AppFramework \Utility \ITimeFactory ;
4142use OCP \DB \QueryBuilder \IQueryBuilder ;
4243use OCP \Defaults ;
4344use OCP \Files \Folder ;
@@ -90,19 +91,19 @@ class DefaultShareProvider implements IShareProvider {
9091 /** @var IURLGenerator */
9192 private $ urlGenerator ;
9293
93- /** @var IConfig */
94- private $ config ;
94+ private ITimeFactory $ timeFactory ;
9595
9696 public function __construct (
97- IDBConnection $ connection ,
98- IUserManager $ userManager ,
99- IGroupManager $ groupManager ,
100- IRootFolder $ rootFolder ,
101- IMailer $ mailer ,
102- Defaults $ defaults ,
103- IFactory $ l10nFactory ,
104- IURLGenerator $ urlGenerator ,
105- IConfig $ config ) {
97+ IDBConnection $ connection ,
98+ IUserManager $ userManager ,
99+ IGroupManager $ groupManager ,
100+ IRootFolder $ rootFolder ,
101+ IMailer $ mailer ,
102+ Defaults $ defaults ,
103+ IFactory $ l10nFactory ,
104+ IURLGenerator $ urlGenerator ,
105+ ITimeFactory $ timeFactory ,
106+ ) {
106107 $ this ->dbConn = $ connection ;
107108 $ this ->userManager = $ userManager ;
108109 $ this ->groupManager = $ groupManager ;
@@ -111,7 +112,7 @@ public function __construct(
111112 $ this ->defaults = $ defaults ;
112113 $ this ->l10nFactory = $ l10nFactory ;
113114 $ this ->urlGenerator = $ urlGenerator ;
114- $ this ->config = $ config ;
115+ $ this ->timeFactory = $ timeFactory ;
115116 }
116117
117118 /**
@@ -216,32 +217,22 @@ public function create(\OCP\Share\IShare $share) {
216217 }
217218
218219 // Set the time this share was created
219- $ qb ->setValue ('stime ' , $ qb ->createNamedParameter (time ()));
220+ $ shareTime = $ this ->timeFactory ->now ();
221+ $ qb ->setValue ('stime ' , $ qb ->createNamedParameter ($ shareTime ->getTimestamp ()));
220222
221223 // insert the data and fetch the id of the share
222- $ this ->dbConn ->beginTransaction ();
223- $ qb ->execute ();
224- $ id = $ this ->dbConn ->lastInsertId ('*PREFIX*share ' );
225-
226- // Now fetch the inserted share and create a complete share object
227- $ qb = $ this ->dbConn ->getQueryBuilder ();
228- $ qb ->select ('* ' )
229- ->from ('share ' )
230- ->where ($ qb ->expr ()->eq ('id ' , $ qb ->createNamedParameter ($ id )));
224+ $ qb ->executeStatement ();
231225
232- $ cursor = $ qb -> execute ();
233- $ data = $ cursor -> fetch ();
234- $ this -> dbConn -> commit ( );
235- $ cursor -> closeCursor ( );
226+ // Update mandatory data
227+ $ id = $ qb -> getLastInsertId ();
228+ $ share -> setId (( string ) $ id );
229+ $ share -> setProviderId ( $ this -> identifier () );
236230
237- if ($ data === false ) {
238- throw new ShareNotFound ('Newly created share could not be found ' );
239- }
231+ $ share ->setShareTime (\DateTime::createFromImmutable ($ shareTime ));
240232
241233 $ mailSendValue = $ share ->getMailSend ();
242- $ data [ ' mail_send ' ] = ( $ mailSendValue === null ) ? true : $ mailSendValue ;
234+ $ share -> setMailSend (( $ mailSendValue === null ) ? true : $ mailSendValue) ;
243235
244- $ share = $ this ->createShare ($ data );
245236 return $ share ;
246237 }
247238
0 commit comments