constans for signals handling
This commit is contained in:
parent
2d25bb3b01
commit
ef69abd4dc
|
@ -21,9 +21,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OC_Hook::connect("OC_Filesystem", "post_write", "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
|
OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
|
||||||
OC_Hook::connect("OC_Filesystem", "delete", "OC_Gallery_Hooks_Handlers", "removePhoto");
|
OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto");
|
||||||
OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Gallery_Hooks_Handlers", "renamePhoto");
|
OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, "OC_Gallery_Hooks_Handlers", "renamePhoto");
|
||||||
|
|
||||||
require_once(OC::$CLASSPATH['OC_Gallery_Album']);
|
require_once(OC::$CLASSPATH['OC_Gallery_Album']);
|
||||||
require_once(OC::$CLASSPATH['OC_Gallery_Photo']);
|
require_once(OC::$CLASSPATH['OC_Gallery_Photo']);
|
||||||
|
@ -61,8 +61,10 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addPhotoFromPath($params) {
|
public static function addPhotoFromPath($params) {
|
||||||
if (!self::isPhoto($params['path'])) return;
|
$fullpath = $params[OC_Filesystem::signal_param_path];
|
||||||
$fullpath = $params['path'];
|
|
||||||
|
if (!self::isPhoto($fullpath)) return;
|
||||||
|
|
||||||
OC_Log::write(self::$APP_TAG, 'Adding file with path '. $fullpath, OC_Log::DEBUG);
|
OC_Log::write(self::$APP_TAG, 'Adding file with path '. $fullpath, OC_Log::DEBUG);
|
||||||
$path = substr($fullpath, 0, strrpos($fullpath, '/'));
|
$path = substr($fullpath, 0, strrpos($fullpath, '/'));
|
||||||
if ($path == '') $path = '/';
|
if ($path == '') $path = '/';
|
||||||
|
@ -82,7 +84,7 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function removePhoto($params) {
|
public static function removePhoto($params) {
|
||||||
$path = $params['path'];
|
$path = $params[OC_Filesystem::signal_param_path];
|
||||||
if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
|
if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
|
||||||
OC_Gallery_Album::removeByPath($path, OC_User::getUser());
|
OC_Gallery_Album::removeByPath($path, OC_User::getUser());
|
||||||
} elseif (self::isPhoto($path)) {
|
} elseif (self::isPhoto($path)) {
|
||||||
|
@ -91,15 +93,17 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function renamePhoto($params) {
|
public static function renamePhoto($params) {
|
||||||
if (OC_Filesystem::is_dir($params['newpath']) && self::directoryContainsPhotos($params['newpath'])) {
|
$oldpath = $params[OC_Filesystem::signal_param_oldpath];
|
||||||
OC_Gallery_Album::changePath($params['oldpath'], $params['newpath'], OC_User::getUser());
|
$newpath = $params[OC_Filesystem::signal_param_newpath];
|
||||||
} elseif (!self::isPhoto($params['newpath'])) {
|
if (OC_Filesystem::is_dir($newpath) && self::directoryContainsPhotos($newpath)) {
|
||||||
$olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/'));
|
OC_Gallery_Album::changePath($oldpath, $newpath, OC_User::getUser());
|
||||||
$newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/'));
|
} elseif (!self::isPhoto($newpath)) {
|
||||||
|
$olddir = substr($oldpath, 0, strrpos($oldpath, '/'));
|
||||||
|
$newdir = substr($newpath, 0, strrpos($newpath, '/'));
|
||||||
if ($olddir == '') $olddir = '/';
|
if ($olddir == '') $olddir = '/';
|
||||||
if ($newdir == '') $newdir = '/';
|
if ($newdir == '') $newdir = '/';
|
||||||
if (!self::isPhoto($params['newpath'])) return;
|
if (!self::isPhoto($newpath)) return;
|
||||||
OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG);
|
OC_Log::write(self::$APP_TAG, 'Moving photo from '.$oldpath.' to '.$newpath, OC_Log::DEBUG);
|
||||||
$album;
|
$album;
|
||||||
$newAlbumId;
|
$newAlbumId;
|
||||||
$oldAlbumId;
|
$oldAlbumId;
|
||||||
|
@ -120,7 +124,7 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
}
|
}
|
||||||
$newalbum = $newalbum->fetchRow();
|
$newalbum = $newalbum->fetchRow();
|
||||||
if ($oldalbum->numRows() == 0) {
|
if ($oldalbum->numRows() == 0) {
|
||||||
OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']);
|
OC_Gallery_Photo::create($newalbum['album_id'], $newpath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$oldalbum = $oldalbum->fetchRow();
|
$oldalbum = $oldalbum->fetchRow();
|
||||||
|
@ -128,7 +132,7 @@ class OC_Gallery_Hooks_Handlers {
|
||||||
$oldAlbumId = $oldalbum['album_id'];
|
$oldAlbumId = $oldalbum['album_id'];
|
||||||
|
|
||||||
}
|
}
|
||||||
OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']);
|
OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,91 @@ class OC_Filesystem{
|
||||||
static private $fakeRoot='';
|
static private $fakeRoot='';
|
||||||
static private $storageTypes=array();
|
static private $storageTypes=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* classname which used for hooks handling
|
||||||
|
* used as signalclass in OC_Hooks::emit()
|
||||||
|
*/
|
||||||
|
const CLASSNAME = 'OC_Filesystem';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signalname emited before file renaming
|
||||||
|
* @param oldpath
|
||||||
|
* @param newpath
|
||||||
|
*/
|
||||||
|
const signal_rename = 'rename';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emited after file renaming
|
||||||
|
* @param oldpath
|
||||||
|
* @param newpath
|
||||||
|
*/
|
||||||
|
const signal_post_rename = 'post_rename';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emited before file/dir creation
|
||||||
|
* @param path
|
||||||
|
* @param run changing this flag to false in hook handler will cancel event
|
||||||
|
*/
|
||||||
|
const signal_create = 'create';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emited after file/dir creation
|
||||||
|
* @param path
|
||||||
|
* @param run changing this flag to false in hook handler will cancel event
|
||||||
|
*/
|
||||||
|
const signal_post_create = 'post_create';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emits before file/dir copy
|
||||||
|
* @param oldpath
|
||||||
|
* @param newpath
|
||||||
|
* @param run changing this flag to false in hook handler will cancel event
|
||||||
|
*/
|
||||||
|
const signal_copy = 'copy';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emits after file/dir copy
|
||||||
|
* @param oldpath
|
||||||
|
* @param newpath
|
||||||
|
*/
|
||||||
|
const signal_post_copy = 'post_copy';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emits before file/dir save
|
||||||
|
* @param path
|
||||||
|
* @param run changing this flag to false in hook handler will cancel event
|
||||||
|
*/
|
||||||
|
const signal_write = 'write';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emits after file/dir save
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
|
const signal_post_write = 'post_write';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emits when reading file/dir
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
|
const signal_read = 'read';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* signal emits when removing file/dir
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
|
const signal_delete = 'delete';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parameters definitions for signals
|
||||||
|
*/
|
||||||
|
const signal_param_path = 'path';
|
||||||
|
const signal_param_oldpath = 'oldpath';
|
||||||
|
const signal_param_newpath = 'newpath';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run - changing this flag to false in hook handler will cancel event
|
||||||
|
*/
|
||||||
|
const signal_param_run = 'run';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* register a storage type
|
* register a storage type
|
||||||
|
@ -285,7 +370,7 @@ class OC_Filesystem{
|
||||||
static public function rename($path1,$path2){
|
static public function rename($path1,$path2){
|
||||||
if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::is_writeable($path1) and self::isValidPath($path2)){
|
if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::is_writeable($path1) and self::isValidPath($path2)){
|
||||||
$run=true;
|
$run=true;
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_rename, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run));
|
||||||
if($run){
|
if($run){
|
||||||
$mp1=self::getMountPoint($path1);
|
$mp1=self::getMountPoint($path1);
|
||||||
$mp2=self::getMountPoint($path2);
|
$mp2=self::getMountPoint($path2);
|
||||||
|
@ -298,7 +383,7 @@ class OC_Filesystem{
|
||||||
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
|
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
|
||||||
$storage1->unlink(self::getInternalPath($path1));
|
$storage1->unlink(self::getInternalPath($path1));
|
||||||
}
|
}
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_rename, array( self::signal_param_oldpath => $path1, self::signal_param_newpath=>$path2));
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,13 +391,13 @@ class OC_Filesystem{
|
||||||
static public function copy($path1,$path2){
|
static public function copy($path1,$path2){
|
||||||
if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::is_readable($path1) and self::isValidPath($path2)){
|
if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::is_readable($path1) and self::isValidPath($path2)){
|
||||||
$run=true;
|
$run=true;
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run));
|
||||||
$exists=self::file_exists($path2);
|
$exists=self::file_exists($path2);
|
||||||
if($run and !$exists){
|
if($run and !$exists){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path2, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path2, self::signal_param_run => &$run));
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path2, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path2, self::signal_param_run => &$run));
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
$mp1=self::getMountPoint($path1);
|
$mp1=self::getMountPoint($path1);
|
||||||
|
@ -325,11 +410,11 @@ class OC_Filesystem{
|
||||||
$tmpFile=$storage1->toTmpFile(self::getInternalPath($path1));
|
$tmpFile=$storage1->toTmpFile(self::getInternalPath($path1));
|
||||||
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
|
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
|
||||||
}
|
}
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_copy', array( 'oldpath' => $path1 ,'newpath'=>$path2));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2));
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path2));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path2));
|
||||||
}
|
}
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path2));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path2));
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,7 +445,7 @@ class OC_Filesystem{
|
||||||
}
|
}
|
||||||
static public function toTmpFile($path){
|
static public function toTmpFile($path){
|
||||||
if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
|
if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, self::signal_read, array( self::signal_param_path => $path));
|
||||||
return $storage->toTmpFile(self::getInternalPath($path));
|
return $storage->toTmpFile(self::getInternalPath($path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,17 +454,17 @@ class OC_Filesystem{
|
||||||
$run=true;
|
$run=true;
|
||||||
$exists=self::file_exists($path);
|
$exists=self::file_exists($path);
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run));
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run));
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
$result=$storage->fromTmpFile($tmpFile,self::getInternalPath($path));
|
$result=$storage->fromTmpFile($tmpFile,self::getInternalPath($path));
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path));
|
||||||
}
|
}
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path));
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,17 +474,17 @@ class OC_Filesystem{
|
||||||
$run=true;
|
$run=true;
|
||||||
$exists=self::file_exists($path);
|
$exists=self::file_exists($path);
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run));
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run));
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
$result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path));
|
$result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path));
|
||||||
if(!$exists){
|
if(!$exists){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path));
|
||||||
}
|
}
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path));
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -453,9 +538,9 @@ class OC_Filesystem{
|
||||||
$run=true;
|
$run=true;
|
||||||
foreach($hooks as $hook){
|
foreach($hooks as $hook){
|
||||||
if($hook!='read'){
|
if($hook!='read'){
|
||||||
OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path, 'run' => &$run));
|
OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path, self::signal_param_run => &$run));
|
||||||
}else{
|
}else{
|
||||||
OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($run){
|
if($run){
|
||||||
|
@ -467,7 +552,7 @@ class OC_Filesystem{
|
||||||
$result=OC_FileProxy::runPostProxies($operation,$path,$result);
|
$result=OC_FileProxy::runPostProxies($operation,$path,$result);
|
||||||
foreach($hooks as $hook){
|
foreach($hooks as $hook){
|
||||||
if($hook!='read'){
|
if($hook!='read'){
|
||||||
OC_Hook::emit( 'OC_Filesystem', 'post_'.$hook, array( 'path' => $path));
|
OC_Hook::emit( self::CLASSNAME, 'post_'.$hook, array( self::signal_param_path => $path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Reference in New Issue