mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-03 20:09:27 +01:00
Add support of storing file contents in the database
This commit is contained in:
parent
80a9931e0d
commit
402b797472
@ -92,6 +92,7 @@
|
|||||||
var $linked_dirs;
|
var $linked_dirs;
|
||||||
var $meta_types;
|
var $meta_types;
|
||||||
var $now;
|
var $now;
|
||||||
|
var $file_actions;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@function vfs
|
@function vfs
|
||||||
@ -130,9 +131,26 @@
|
|||||||
'name',
|
'name',
|
||||||
'link_directory',
|
'link_directory',
|
||||||
'link_name',
|
'link_name',
|
||||||
'version'
|
'version',
|
||||||
|
'content'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Decide whether to use any actual filesystem calls (fopen(), fread(),
|
||||||
|
unlink(), rmdir(), touch(), etc.). If not, then we're working completely
|
||||||
|
in the database.
|
||||||
|
*/
|
||||||
|
$conf = CreateObject('phpgwapi.config', 'phpgwapi');
|
||||||
|
$conf->read_repository();
|
||||||
|
if ($conf->config_data['file_store_contents'] == 'filesystem' || !$conf->config_data['file_store_contents'])
|
||||||
|
{
|
||||||
|
$this->file_actions = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->file_actions = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These are stored in the MIME-type field and should normally be ignored.
|
These are stored in the MIME-type field and should normally be ignored.
|
||||||
Adding a type here will ensure it is normally ignored, but you will have to
|
Adding a type here will ensure it is normally ignored, but you will have to
|
||||||
@ -374,7 +392,7 @@
|
|||||||
|
|
||||||
for ($i = 0; list ($attribute, $value) = each ($file_array); $i++)
|
for ($i = 0; list ($attribute, $value) = each ($file_array); $i++)
|
||||||
{
|
{
|
||||||
if ($attribute == 'file_id')
|
if ($attribute == 'file_id' || $attribute == 'content')
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1388,6 +1406,10 @@
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$conf = CreateObject('phpgwapi.config', 'phpgwapi');
|
||||||
|
$conf->read_repository();
|
||||||
|
if ($this->file_actions || $p->outside)
|
||||||
|
{
|
||||||
if ($fp = fopen ($p->real_full_path, 'rb'))
|
if ($fp = fopen ($p->real_full_path, 'rb'))
|
||||||
{
|
{
|
||||||
$contents = fread ($fp, filesize ($p->real_full_path));
|
$contents = fread ($fp, filesize ($p->real_full_path));
|
||||||
@ -1397,6 +1419,17 @@
|
|||||||
{
|
{
|
||||||
$contents = False;
|
$contents = False;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$ls_array = $this->ls (array(
|
||||||
|
'string' => $p->fake_full_path,
|
||||||
|
'relatives' => array ($p->mask),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$contents = $ls_array[0]['content'];
|
||||||
|
}
|
||||||
|
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
@ -1466,15 +1499,40 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$conf = CreateObject('phpgwapi.config', 'phpgwapi');
|
||||||
|
$conf->read_repository();
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
if ($fp = fopen ($p->real_full_path, 'wb'))
|
if ($fp = fopen ($p->real_full_path, 'wb'))
|
||||||
{
|
{
|
||||||
fwrite ($fp, $data['content'], strlen ($data['content']));
|
fwrite ($fp, $data['content'], strlen ($data['content']));
|
||||||
fclose ($fp);
|
fclose ($fp);
|
||||||
|
$write_ok = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->set_attributes (array(
|
if ($write_ok || !$this->file_actions)
|
||||||
|
{
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
|
$set_attributes_array = array(
|
||||||
|
'size' => filesize ($p->real_full_path)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$set_attributes_array = array (
|
||||||
|
'size' => strlen ($data['content']),
|
||||||
|
'content' => $data['content']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$this->set_attributes (array
|
||||||
|
(
|
||||||
'string' => $p->fake_full_path,
|
'string' => $p->fake_full_path,
|
||||||
'relatives' => array ($p->mask),
|
'relatives' => array ($p->mask),
|
||||||
'attributes' => array ('size' => filesize ($p->real_full_path))
|
'attributes' => $set_attributes_array
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1528,6 +1586,8 @@
|
|||||||
|
|
||||||
umask (000);
|
umask (000);
|
||||||
|
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
PHP's touch function will automatically decide whether to
|
PHP's touch function will automatically decide whether to
|
||||||
create the file or set the modification time
|
create the file or set the modification time
|
||||||
@ -1538,6 +1598,7 @@
|
|||||||
{
|
{
|
||||||
return $rr;
|
return $rr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* We, however, have to decide this ourselves */
|
/* We, however, have to decide this ourselves */
|
||||||
if ($this->file_exists (array(
|
if ($this->file_exists (array(
|
||||||
@ -1698,19 +1759,32 @@
|
|||||||
'relatives' => array ($f->mask)
|
'relatives' => array ($f->mask)
|
||||||
)) != 'Directory'
|
)) != 'Directory'
|
||||||
)
|
)
|
||||||
|
{
|
||||||
|
if ($this->file_actions)
|
||||||
{
|
{
|
||||||
if (!copy ($f->real_full_path, $t->real_full_path))
|
if (!copy ($f->real_full_path, $t->real_full_path))
|
||||||
{
|
{
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$size = filesize ($t->real_full_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$content = $this->read (array(
|
||||||
|
'string' => $f->fake_full_path,
|
||||||
|
'relatives' => array ($f->mask)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$size = strlen ($content);
|
||||||
|
}
|
||||||
|
|
||||||
if ($t->outside)
|
if ($t->outside)
|
||||||
{
|
{
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
$size = filesize ($t->real_full_path);
|
|
||||||
|
|
||||||
$ls_array = $this->ls (array(
|
$ls_array = $this->ls (array(
|
||||||
'string' => $f->fake_full_path,
|
'string' => $f->fake_full_path,
|
||||||
'relatives' => array ($f->mask),
|
'relatives' => array ($f->mask),
|
||||||
@ -1729,10 +1803,7 @@
|
|||||||
{
|
{
|
||||||
$query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET owner_id='$this->working_id', directory='$t->fake_leading_dirs_clean', name='$t->fake_name_clean' WHERE owner_id='$this->working_id' AND directory='$t->fake_leading_dirs_clean' AND name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__);
|
$query = $GLOBALS['phpgw']->db->query ("UPDATE phpgw_vfs SET owner_id='$this->working_id', directory='$t->fake_leading_dirs_clean', name='$t->fake_name_clean' WHERE owner_id='$this->working_id' AND directory='$t->fake_leading_dirs_clean' AND name='$t->fake_name_clean'" . $this->extra_sql (VFS_SQL_UPDATE), __LINE__, __FILE__);
|
||||||
|
|
||||||
$this->set_attributes(array(
|
$set_attributes_array = array (
|
||||||
'string' => $t->fake_full_path,
|
|
||||||
'relatives' => array ($t->mask),
|
|
||||||
'attributes' => array (
|
|
||||||
'createdby_id' => $account_id,
|
'createdby_id' => $account_id,
|
||||||
'created' => $this->now,
|
'created' => $this->now,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
@ -1740,7 +1811,17 @@
|
|||||||
'deleteable' => $record['deleteable'],
|
'deleteable' => $record['deleteable'],
|
||||||
'comment' => $record['comment'],
|
'comment' => $record['comment'],
|
||||||
'app' => $record['app']
|
'app' => $record['app']
|
||||||
)
|
);
|
||||||
|
|
||||||
|
if (!$this->file_actions)
|
||||||
|
{
|
||||||
|
$set_attributes_array['content'] = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->set_attributes(array(
|
||||||
|
'string' => $t->fake_full_path,
|
||||||
|
'relatives' => array ($t->mask),
|
||||||
|
'attributes' => $set_attributes_array
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1759,10 +1840,7 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->set_attributes(array(
|
$set_attributes_array = array (
|
||||||
'string' => $t->fake_full_path,
|
|
||||||
'relatives' => array ($t->mask),
|
|
||||||
'attributes' => array (
|
|
||||||
'createdby_id' => $account_id,
|
'createdby_id' => $account_id,
|
||||||
'created' => $this->now,
|
'created' => $this->now,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
@ -1770,7 +1848,17 @@
|
|||||||
'deleteable' => $record['deleteable'],
|
'deleteable' => $record['deleteable'],
|
||||||
'comment' => $record['comment'],
|
'comment' => $record['comment'],
|
||||||
'app' => $record['app']
|
'app' => $record['app']
|
||||||
)
|
);
|
||||||
|
|
||||||
|
if (!$this->file_actions)
|
||||||
|
{
|
||||||
|
$set_attributes_array['content'] = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->set_attributes(array(
|
||||||
|
'string' => $t->fake_full_path,
|
||||||
|
'relatives' => array ($t->mask),
|
||||||
|
'attributes' => $set_attributes_array
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -2024,7 +2112,10 @@
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
$rr = rename ($f->real_full_path, $t->real_full_path);
|
$rr = rename ($f->real_full_path, $t->real_full_path);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This removes the original entry from the database
|
This removes the original entry from the database
|
||||||
@ -2128,8 +2219,15 @@
|
|||||||
'relatives' => array ($data['relatives'][0])
|
'relatives' => array ($data['relatives'][0])
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
{
|
||||||
|
if ($this->file_actions)
|
||||||
{
|
{
|
||||||
$rr = unlink ($p->real_full_path);
|
$rr = unlink ($p->real_full_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$rr = True;
|
||||||
|
}
|
||||||
|
|
||||||
if ($rr)
|
if ($rr)
|
||||||
{
|
{
|
||||||
@ -2155,7 +2253,15 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
$query = $GLOBALS['phpgw']->db->query ("DELETE FROM phpgw_vfs WHERE directory='".$p->fake_leading_dirs_clean."' AND name='".$p->fake_name_clean."'".$this->extra_sql (array ('query_type' => VFS_SQL_DELETE)), __LINE__, __FILE__);
|
$query = $GLOBALS['phpgw']->db->query ("DELETE FROM phpgw_vfs WHERE directory='".$p->fake_leading_dirs_clean."' AND name='".$p->fake_name_clean."'".$this->extra_sql (array ('query_type' => VFS_SQL_DELETE)), __LINE__, __FILE__);
|
||||||
|
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
$rr = unlink ($p->real_full_path);
|
$rr = unlink ($p->real_full_path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$rr = True;
|
||||||
|
}
|
||||||
|
|
||||||
if ($query || $rr)
|
if ($query || $rr)
|
||||||
{
|
{
|
||||||
@ -2225,8 +2331,12 @@
|
|||||||
'nolinks' => True
|
'nolinks' => True
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
rmdir ($path->real_full_path);
|
rmdir ($path->real_full_path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Last, we delete the directory itself */
|
/* Last, we delete the directory itself */
|
||||||
$this->add_journal (array(
|
$this->add_journal (array(
|
||||||
@ -2238,7 +2348,10 @@
|
|||||||
|
|
||||||
$query = $GLOBALS['phpgw']->db->query ("DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (array ('query_type' => VFS_SQL_DELETE)), __LINE__, __FILE__);
|
$query = $GLOBALS['phpgw']->db->query ("DELETE FROM phpgw_vfs WHERE directory='$p->fake_leading_dirs_clean' AND name='$p->fake_name_clean'" . $this->extra_sql (array ('query_type' => VFS_SQL_DELETE)), __LINE__, __FILE__);
|
||||||
|
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
rmdir ($p->real_full_path);
|
rmdir ($p->real_full_path);
|
||||||
|
}
|
||||||
|
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
@ -2301,10 +2414,13 @@
|
|||||||
|
|
||||||
umask (000);
|
umask (000);
|
||||||
|
|
||||||
|
if ($this->file_actions)
|
||||||
|
{
|
||||||
if (!@mkdir ($p->real_full_path, 0770))
|
if (!@mkdir ($p->real_full_path, 0770))
|
||||||
{
|
{
|
||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$this->file_exists (array(
|
if (!$this->file_exists (array(
|
||||||
'string' => $p->fake_full_path,
|
'string' => $p->fake_full_path,
|
||||||
@ -2449,22 +2565,7 @@
|
|||||||
@param relatives Relativity array
|
@param relatives Relativity array
|
||||||
@param attributes keyed array of attributes. key is attribute name, value is attribute value
|
@param attributes keyed array of attributes. key is attribute name, value is attribute value
|
||||||
@result Boolean True/False
|
@result Boolean True/False
|
||||||
@discussion Valid attributes are:
|
@discussion Valid attributes are list in vfs->attributes
|
||||||
owner_id
|
|
||||||
createdby_id
|
|
||||||
modifiedby_id
|
|
||||||
created
|
|
||||||
modified
|
|
||||||
size
|
|
||||||
mime_type
|
|
||||||
deleteable
|
|
||||||
comment
|
|
||||||
app
|
|
||||||
link_directory
|
|
||||||
link_name
|
|
||||||
version
|
|
||||||
name
|
|
||||||
directory
|
|
||||||
*/
|
*/
|
||||||
function set_attributes ($data)
|
function set_attributes ($data)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user