Hi All,
Following the developper documentation, I’m trying to refer the root storage in one of my service like
$container = $this->getContainer();
$container->registerService('MyService', function($c) {
return new MyService(
$c->query('AppName'),
$c->query('Logger'),
$c->query('RootStorage')
);
});
$container->registerService('RootStorage', function($c) {
return $c->query('ServerContainer')->getRootFolder();
});
$container->registerService('Logger',function($c){
return $c->query('ServerContainer')->getLogger();
});
class MyService{
private $storage;
private $appName;
private $logger;
public function __construct($appName, ILogger $logger, $storage) {
$this->appName = $appName;
$this->logger = $logger;
$this->storage = $storage;
}
public function MyMethod() {
....
}
}
When I call method MyMethod on the MyService, I receive an error about MyService is null.
If I remove the ‘RootStorage’ reference on MyService is not null any more.
Could you help me to fix this issue ?
Thanks,
Yannick
Annotate $storage with IRootFolder (and import that). That will give you a bette error.
Thanks for your answer.
I do some change in my MyService class like
use OCP\ILogger;
use OCP\IRootFolder;
public function __construct($appName, ILogger $logger, IRootFolder $storage) {
$this->appName = $appName;
$this->logger = $logger;
$this->storage = $storage;
}
but MyService is always null.
Perhaps an inclusion is missing.
I need a specific declaration in Application.php to use getRootFolder() ?
Where is MyService null?`
When I call it from a command
If I remove the storage from the constructor and application, it’s working
I found, inclusion is not OCP\IRootFolder but OCP\Files\IRootFolder
Now, I’m trying to write in a folder from an occ command and I receive an OCP\Files\NotPermittedException
Any idea?
I try to create a file in the admin users store, so I try to “touch” a file in /admin/files/myfile.txt
The folder is available
In fact, the file is present in the directory, but not visible in the web interface … strange
I must do a occ file:scan --all to register files/folder.
Strange if I use the framework to save it…
What folder do you try to write in
From Nextcloud UI, I create a folder in the admin users storage named TEST.
I want to create a subfolder based on the current date.
$date = date('Y-m-d');
$folder = "admin/files/TEST/".$date;
$this->storage->newFolder($folder);
The folder is correctly create in the file system, but not visibile in the UI.
I must run occ files:scan admin
try to get the admin user folder (check the interface)
1 Like
getUserFolder() insteadOf getRootFolder() ?
It’s perfect. It’s working as fine !
Thanks a lot.