1313use OCA \UserMigration \AppInfo \Application ;
1414use OCA \UserMigration \Service \UserMigrationService ;
1515use OCP \AppFramework \Utility \ITimeFactory ;
16+ use OCP \DB \QueryBuilder \IQueryBuilder ;
1617use OCP \IConfig ;
1718use OCP \IDBConnection ;
1819use OCP \IUserManager ;
@@ -45,6 +46,12 @@ protected function configure(): void {
4546 'Limit the number of listed users ' ,
4647 100 ,
4748 )
49+ ->addOption (
50+ 'since ' ,
51+ null ,
52+ InputOption::VALUE_REQUIRED ,
53+ 'Filter by minimum export date ' ,
54+ )
4855 ->addOption (
4956 'delete ' ,
5057 null ,
@@ -54,7 +61,13 @@ protected function configure(): void {
5461 }
5562
5663 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
57- $ values = iterator_to_array ($ this ->queryUsers ((int )$ input ->getOption ('limit ' )));
64+ if ((string )$ input ->getOption ('since ' ) !== '' ) {
65+ $ since = new \DateTime ($ input ->getOption ('since ' ));
66+ $ output ->writeln ('<info>Since ' . $ since ->format (\DateTimeInterface::ATOM ) . '</info> ' );
67+ } else {
68+ $ since = null ;
69+ }
70+ $ values = iterator_to_array ($ this ->queryUsers ((int )$ input ->getOption ('limit ' ), $ since ));
5871 $ this ->writeTableInOutputFormat ($ input , $ output , $ values );
5972 if ($ input ->getOption ('delete ' )) {
6073 /** @var QuestionHelper $helper */
@@ -73,13 +86,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7386 return self ::SUCCESS ;
7487 }
7588
76- private function queryUsers (int $ limit ): \Generator {
89+ private function queryUsers (int $ limit, ? \ DateTime $ since ): \Generator {
7790 $ qb = $ this ->connection ->getQueryBuilder ();
7891 $ qb ->select ('userid ' , 'configvalue ' )
7992 ->from ('preferences ' )
8093 ->where ($ qb ->expr ()->eq ('appid ' , $ qb ->createNamedParameter (Application::APP_ID )))
81- ->andWhere ($ qb ->expr ()->eq ('configkey ' , $ qb ->createNamedParameter ('lastExport ' )))
82- ->orderBy ('configvalue ' )
94+ ->andWhere ($ qb ->expr ()->eq ('configkey ' , $ qb ->createNamedParameter ('lastExport ' )));
95+
96+ if ($ since !== null ) {
97+ $ qb ->andWhere ($ qb ->expr ()->gte ('configvalue ' , $ qb ->createNamedParameter ($ since ->getTimestamp (), IQueryBuilder::PARAM_INT )));
98+ }
99+
100+ $ qb ->orderBy ('configvalue ' )
83101 ->setMaxResults ($ limit );
84102
85103 $ result = $ qb ->executeQuery ();
0 commit comments