Skip to content

Commit

Permalink
Work on modulebuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 28, 2017
1 parent c651f1d commit c4f09b8
Show file tree
Hide file tree
Showing 23 changed files with 305 additions and 108 deletions.
2 changes: 2 additions & 0 deletions dev/translation/sanity_check_en_langfiles.php
Expand Up @@ -310,6 +310,8 @@
if (preg_match('/^.*Bytes$/', $value)) $qualifiedforclean=0;
if (preg_match('/^NoteSomeFeaturesAreDisabled/', $value)) $qualifiedforclean=0;
if (preg_match('/^(DoTest|Under|Limits|Cards|CurrentValue|DateLimit|DateAndHour|NbOfLines|NbOfObjects|NbOfReferes|TotalTTCShort|VATs)/', $value)) $qualifiedforclean=0;
// modulebuilder
if (preg_match('/^ModuleBuilderDesc/', $value)) $qualifiedforclean=0;
// orders
if (preg_match('/^OrderSource/', $value)) $qualifiedforclean=0;
if (preg_match('/^TypeContact_/', $value)) $qualifiedforclean=0;
Expand Down
1 change: 0 additions & 1 deletion htdocs/admin/triggers.php
Expand Up @@ -47,7 +47,6 @@
print $langs->trans("TriggersDesc")."<br>";
print "<br>\n";

$template_dir = DOL_DOCUMENT_ROOT.'/core/tpl/';

$interfaces = new Interfaces($db);
$triggers = $interfaces->getTriggersList();
Expand Down
11 changes: 8 additions & 3 deletions htdocs/core/class/interfaces.class.php
Expand Up @@ -226,9 +226,10 @@ function run_triggers($action,$object,$user,$langs,$conf)
* Return list of triggers. Function used by admin page htdoc/admin/triggers.
* List is sorted by trigger filename so by priority to run.
*
* @return array Array list of triggers
* @param array $forcedirtriggers null=All default directories. This parameter is used by modulebuilder module only.
* @return array Array list of triggers
*/
function getTriggersList()
function getTriggersList($forcedirtriggers=null)
{
global $conf, $langs;

Expand All @@ -241,11 +242,15 @@ function getTriggersList()
$i = 0;

$dirtriggers=array_merge(array('/core/triggers/'),$conf->modules_parts['triggers']);
if (is_array($forcedirtriggers))
{
$dirtriggers=$forcedirtriggers;
}

foreach($dirtriggers as $reldir)
{
$dir=dol_buildpath($reldir,0);
$newdir=dol_osencode($dir);
//print "xx".$dir;exit;

// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
if (! is_dir($newdir)) continue;
Expand Down
65 changes: 36 additions & 29 deletions htdocs/core/lib/files.lib.php
Expand Up @@ -448,14 +448,15 @@ function dol_filemtime($pathoffile)
* @param array $arrayreplacement Array with strings to replace
* @param string $destfile Destination file (can't be a directory). If empty, will be same than source file.
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $indexdatabase Index new file into database.
* @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK
* @see dolCopyr
*/
function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0)
function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0)
{
global $conf;

dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask);
dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase);

if (empty($srcfile)) return -1;
if (empty($destfile)) $destfile=$srcfile;
Expand Down Expand Up @@ -484,12 +485,15 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0)
dol_delete_file($tmpdestfile);

// Create $newpathoftmpdestfile from $newpathofsrcfile
$content=file_get_contents($newpathofsrcfile, 'r');

$content = make_substitutions($content, $arrayreplacement, null);


file_put_contents($newpathoftmpdestfile, $content);
@chmod($newpathoftmpdestfile, octdec($newmask));

// Rename
$result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0));
$result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase);
if (! $result)
{
dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
Expand Down Expand Up @@ -569,10 +573,11 @@ function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
* @param string $destfile Destination file (a directory)
* @param int $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK). Example: '0666'
* @param int $overwriteifexists Overwrite file if exists (1 by default)
* @return int <0 if error, 0 if nothing done (dest dir already exists and overwriteifexists=0), >0 if OK
* @param array $arrayreplacement Array to use to replace filenames with another one during the copy (works only on file names, not on directory names).
* @return int <0 if error, 0 if nothing done (all files already exists and overwriteifexists=0), >0 if OK
* @see dol_copy
*/
function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null)
{
global $conf;

Expand All @@ -583,7 +588,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
if (empty($srcfile) || empty($destfile)) return -1;

$destexists=dol_is_dir($destfile);
if (! $overwriteifexists && $destexists) return 0;
//if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propaated to dol_copy only.

if (! $destexists)
{
Expand All @@ -592,37 +597,37 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
$dirmaskdec=octdec($newmask);
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
$dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files
dol_mkdir($destfile."/".$file, '', decoct($dirmaskdec));
dol_mkdir($destfile, '', decoct($dirmaskdec));
}

$srcfile=dol_osencode($srcfile);
$destfile=dol_osencode($destfile);
$ossrcfile=dol_osencode($srcfile);
$osdestfile=dol_osencode($destfile);

// recursive function to copy
// all subdirectories and contents:
if (is_dir($srcfile))
// Recursive function to copy all subdirectories and contents:
if (is_dir($ossrcfile))
{
$dir_handle=opendir($srcfile);
$dir_handle=opendir($ossrcfile);
while ($file=readdir($dir_handle))
{
if ($file!="." && $file!="..")
{
if (is_dir($srcfile."/".$file))
if (is_dir($ossrcfile."/".$file))
{
if (!is_dir($destfile."/".$file))
{
// We must set mask just before creating dir, becaause it can be set differently by dol_copy
umask(0);
$dirmaskdec=octdec($newmask);
if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK);
$dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files
dol_mkdir($destfile."/".$file, '', decoct($dirmaskdec));
}
$tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists);
//var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists");
$tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement);
}
else
{
$tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists);
$newfile = $file;
// Replace destination filename with a new one
if (is_array($arrayreplacement))
{
foreach($arrayreplacement as $key => $val)
{
$newfile = str_replace($key, $val, $newfile);
}
}
$tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists);
}
// Set result
if ($result > 0 && $tmpresult >= 0)
Expand All @@ -641,7 +646,8 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
}
else
{
$result=dol_copy($srcfile, $destfile, $newmask, $overwriteifexists);
// Source directory does not exists
$result = -2;
}

return $result;
Expand All @@ -660,10 +666,11 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists)
* @param integer $newmask Mask in octal string for new file (0 by default means $conf->global->MAIN_UMASK)
* @param int $overwriteifexists Overwrite file if exists (1 by default)
* @param int $testvirus Do an antivirus test. Move is canceled if a virus is found.
* @param int $indexdatabase Index new file into database.
* @return boolean True if OK, false if KO
* @see dol_move_uploaded_file
*/
function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0)
function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
{
global $user, $db, $conf;
$result=false;
Expand Down Expand Up @@ -709,7 +716,7 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvi
}

// Move ok
if ($result)
if ($result && $indexdatabase)
{
// Rename entry into ecm database
$rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile);
Expand Down
10 changes: 9 additions & 1 deletion htdocs/langs/en_US/modulebuilder.lang
Expand Up @@ -6,4 +6,12 @@ ModuleBuilderDesc3=Generated/editable modules found: <strong>%s</strong> (they a
NewModule=New module
ModuleKey=Key for new module
ModuleInitialized=Module initialized

ModuleBuilderDescdescription=Enter here all general information that describe your module
ModuleBuilderDescobjects=Define here the new objects you want to manage with our module. A page to list them and a page to create/edit/view a card will be generated.
ModuleBuilderDescmenus=This tab is dedicated to define menu entries provided by your module.
ModuleBuilderDescpermissions=This tab is dedicated to define the new permissions you want to provide with our module.
ModuleBuilderDesctriggers=This is the view of triggers provided by your module. To include code executed when a triggered business event is launched, just edit this file with your IDE.
ModuleBuilderDescbuildpackage=You can generate here a "ready to distribute" package file (a normalized .zip file) of your module. Just click on button to get your module package file.
BuildPackage=Build package
ModuleIsNotActive=This module was not activated yet (go into Home-Setup-Module to make it live)
ModuleIsLive=This module has been activated. Any change on it may break a current active feature.

0 comments on commit c4f09b8

Please sign in to comment.