Exemplo n.º 1
0
 public function destroy($p)
 {
     $rez = array('succes' => true, 'data' => array());
     DB\dbQuery('DELETE
         FROM favorites
         WHERE user_id = $1
             AND object_id = $2', array($_SESSION['user']['id'], intval($p['data']))) or die(DB\dbQueryError());
     return $rez;
 }
Exemplo n.º 2
0
 public static function onScriptShutdown()
 {
     Cache::remove('memory');
     if (!is_null($err = error_get_last()) && !in_array($err['type'], array(E_NOTICE, E_WARNING))) {
         DB\dbQuery('UPDATE file_previews
             SET `status` = 3
             WHERE status = 2') or die(DB\dbQueryError());
         DB\commitTransaction();
     }
 }
Exemplo n.º 3
0
 /**
  * get countries list with their phone codes
  *
  * this function returns an array of records for arrayReader
  *     first column is id
  *     second is name
  *     third is phone code
  * @return json response
  */
 public function getCountries()
 {
     $rez = array();
     $res = DB\dbQuery('SELECT
             id
             ,name
             ,phone_codes
         FROM ' . PREFIX . '_casebox.country_phone_codes
         ORDER BY name') or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $rez[] = array_values($r);
     }
     return array('success' => true, 'data' => $rez);
 }
Exemplo n.º 4
0
 /**
  *  returns CB nodes as simple array
  *  @param  int $id          [description]
  *  @param  string $path     [description]
  *  @param  string $level    depth
  *  @param  ary $env
  *  @return [type]           [description]
  */
 public static function getChildren($id, $path, $env, $fileId)
 {
     // error_log('WebDAV/Utils.getChildren(' . $id . ',' . $path . ')');
     $defaultFileTemplate = \CB\Config::get('default_file_template');
     $data = Utils::solrGetChildren($id, $fileId);
     // process SOLR results into a simple array
     $fileIds = array();
     $ary = array();
     foreach ($data->response->docs as $item) {
         $el = array('id' => $item->id, 'name' => $item->name, 'template_id' => $item->template_id, 'size' => $item->size, 'cdate' => $item->cdate, 'uid' => $item->uid, 'udate' => $item->udate, 'path' => $path . DIRECTORY_SEPARATOR . $item->name);
         // PropertyStorage will use filename as path, without the 'edit-{nodeId}' folder
         if ($env['mode'] == 'edit') {
             $el['path'] = $item->name;
         }
         // remember Files: more properties will be fetched below
         if ($item->template_id == $defaultFileTemplate) {
             $fileIds[] = $el['id'];
         }
         $ary[$el['id']] = $el;
     }
     // fetch additional info required for files
     // !!! to be refactored using CB API
     // are there any files in Directory?
     if (!empty($fileIds)) {
         $res = \CB\DB\dbQuery('SELECT
                 f.id
                 ,CONCAT(c.path, \'/\', f.content_id) `content_path`
                 ,c.md5
                 ,c.type
             FROM files f
             LEFT JOIN files_content c ON f.content_id = c.id
             WHERE f.id in (' . implode(',', $fileIds) . ')') or die(DB\dbQueryError());
         // append additional file info (content_path, MD5, type)
         while ($r = $res->fetch_assoc()) {
             $ary[$r['id']] = array_merge($ary[$r['id']], $r);
         }
         $res->close();
     }
     // save the nodes in Cache for later use in WebDAV\PropertyStorage (creationdate and other props)
     Utils::cacheNodes($ary);
     return $ary;
 }
Exemplo n.º 5
0
 public function getChildren($p)
 {
     $p['from'] = 'tree';
     $rez = parent::getChildren($p);
     $sql = 'SELECT count(*) `has_childs`
         FROM tree
         WHERE pid = $1
             AND dstatus = 0' . (empty($p['showFoldersContent']) ? ' AND `template_id` IN (0' . implode(',', Config::get('folder_templates')) . ')' : '');
     foreach ($rez['data'] as &$d) {
         if (!isset($d['loaded'])) {
             if (is_numeric($d['nid'])) {
                 $res = DB\dbQuery($sql, $d['nid']) or die(DB\dbQueryError());
                 if ($r = $res->fetch_assoc()) {
                     $d['has_childs'] = !empty($r['has_childs']);
                 }
                 $res->close();
             }
             $d['loaded'] = empty($d['has_childs']);
         }
     }
     return $rez['data'];
 }
Exemplo n.º 6
0
 public static function getNodeContent($id, $myPath, $onlyFileId = null)
 {
     $s = new \CB\Search();
     $query = 'pid:' . $id;
     $params = array('fl' => 'id,name,template_id,date,cdate,udate,size', 'fq' => array('dstatus:0', 'system:[0 TO 1]'), 'sort' => 'sort_name asc');
     if (is_array($onlyFileId)) {
         $params['fq'][] = 'id:(' . implode(' OR ', $onlyFileId) . ')';
     }
     $data = $s->search($query, 0, 9999, $params);
     $fileIds = array();
     $array = array();
     foreach ($data->response->docs as $item) {
         $el = array('id' => $item->id, 'name' => $item->name, 'template_id' => $item->template_id, 'size' => $item->size, 'cdate' => $item->cdate, 'udate' => $item->udate, 'path' => $myPath . DIRECTORY_SEPARATOR . $item->name);
         if ($item->template_id != \CB\Config::get('default_file_template')) {
             $el['path'] = $myPath . DIRECTORY_SEPARATOR . $item->name;
         } else {
             $fileIds[] = $el['id'];
         }
         $array[$el['id']] = $el;
     }
     /* select additional info required for files */
     if (!empty($fileIds)) {
         $res = \CB\DB\dbQuery('SELECT
                 f.id
                 ,CONCAT(c.path, \'/\', f.content_id) `content_path`
                 ,c.md5
                 ,c.type
             FROM files f
             LEFT JOIN files_content c ON f.content_id = c.id
             WHERE f.id in (' . implode(',', $fileIds) . ')') or die(DB\dbQueryError());
         while ($r = $res->fetch_assoc()) {
             $array[$r['id']] = array_merge($array[$r['id']], $r);
         }
         $res->close();
     }
     return $array;
 }
function onScriptShutdown()
{
    Cache::remove('memory');
    if (!is_null($err = error_get_last()) && !in_array($err['type'], array(E_NOTICE, E_WARNING))) {
        //mark last processed file to be skipped parsing
        $id = Cache::get('lastRecId', false);
        if (!empty($id)) {
            DB\dbQuery('UPDATE files_content
                SET skip_parsing = 1
                WHERE id = $1', $id) or die(DB\dbQueryError());
        }
    }
}
Exemplo n.º 8
0
/**
 * mark a cron as finished
 * @param  varchar $cron_id cron name
 * @return void
 */
function closeCron($cron_id, $info = 'ok')
{
    $scriptOptions = \CB\Cache::get('scriptOptions');
    if (!empty($scriptOptions['force'])) {
        return;
    }
    try {
        $QUERY = 'UPDATE crons
            SET last_end_time = CURRENT_TIMESTAMP, execution_info = $2
            WHERE cron_id = $1';
        DB\dbQuery($QUERY, array($cron_id, $info));
    } catch (Exception $exc) {
        trigger_error($QUERY . print_r(array($cron_id, $info), true) . DB\dbQueryError(), E_USER_WARNING);
    }
}
Exemplo n.º 9
0
 /**
  * get core config stored in database
  *
  * TODO: remove this method after config migration
  * @return array
  */
 private static function getCoreDBConfig()
 {
     $rez = array();
     $res = DB\dbQuery('SELECT param
             ,`value`
         FROM config') or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $rez[$r['param']] = $r['value'];
     }
     $res->close();
     return $rez;
 }
Exemplo n.º 10
0
 public function execute()
 {
     $this->init();
     $processing = false;
     $res = DB\dbQuery('SELECT count(*) `count`
         FROM file_previews
         WHERE `status` = 2
             AND `group` = $1', 'office') or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         $processing = $r['count'] > 0;
     }
     $res->close();
     if ($processing) {
         exit(0);
     }
     $filesPreviewDir = Config::get('files_preview_dir');
     $sql = 'SELECT c.id `content_id`, c.path, p.status
                 ,(SELECT name
                     FROM files f
                     WHERE f.content_id = c.id LIMIT 1
                 ) `name`
             FROM file_previews p
             LEFT JOIN files_content c ON p.id = c.id
             WHERE p.`status` = 1
                 AND `group` = \'office\'
             ORDER BY p.cdate';
     $res = DB\dbQuery($sql) or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         //start the transaction so that the file status would not change on script fail
         DB\startTransaction();
         DB\dbQuery('UPDATE file_previews
             SET `status` = 2
             WHERE id = $1', $r['content_id']) or die(DB\dbQueryError());
         $ext = explode('.', $r['name']);
         $ext = array_pop($ext);
         $ext = strtolower($ext);
         $fn = Config::get('files_dir') . $r['path'] . DIRECTORY_SEPARATOR . $r['content_id'];
         $nfn = $filesPreviewDir . $r['content_id'] . '_.' . $ext;
         $pfn = $filesPreviewDir . $r['content_id'] . '_.html';
         copy($fn, $nfn);
         file_put_contents($pfn, '');
         $cmd = Config::get('UNOCONV') . ' -v -f html -o ' . $pfn . ' ' . $nfn;
         //.' >> ' . Config::get('debug_log') . ' 2>&1';
         exec($cmd, $output, $returnStatus);
         //returnStatus should be 0 if no error
         //we cant delete the file right away
         //because command can execute in background and could take some time
         //unlink($nfn);
         if (empty($returnStatus) && file_exists($pfn)) {
             file_put_contents($pfn, '<div style="padding: 5px">' . $this->purify(file_get_contents($pfn), array('URI.Base' => '/' . Config::get('core_name') . '/view/', 'URI.MakeAbsolute' => true)) . '</div>');
             DB\dbQuery('UPDATE file_previews
                 SET `status` = 0
                     ,`filename` = $2
                     ,`size` = $3
                 WHERE id = $1', array($r['content_id'], $r['content_id'] . '_.html', filesize($pfn))) or die(DB\dbQueryError());
             $res->close();
         } else {
             //preview not generated for some reason, probably unoconv service not started
             \CB\debug('UNOCONV execution error, please check if python accesible through command line' . ' and if correctly specified in config.ini: ' . $cmd);
             DB\dbQuery('UPDATE file_previews
                 SET `status` = 3
                 WHERE id = $1', $r['content_id']) or die(DB\dbQueryError());
         }
         DB\commitTransaction();
         $res = DB\dbQuery($sql) or die(DB\dbQueryError());
     }
     $res->close();
 }
Exemplo n.º 11
0
 public function removeFromQueue($id)
 {
     dbQuery('delete from file_previews where id = $1', $id) or die(DB\dbQueryError());
 }
Exemplo n.º 12
0
        } else {
            $top = '';
            // $tmp = Tasks::getActiveTasksBlockForPreview($id);
            // if (!empty($tmp)) {
            //     $top = '<div class="obj-preview-h pt10">'.L\get('ActiveTasks').'</div>'.$tmp;
            // }
            if (!empty($top)) {
                echo $top . '<hr />';
            }
            if (!empty($preview['filename'])) {
                $fn = $filesPreviewDir . $preview['filename'];
                if (file_exists($fn)) {
                    echo file_get_contents($fn);
                    $res = DB\dbQuery('UPDATE file_previews
                        SET ladate = CURRENT_TIMESTAMP
                        WHERE id = $1', $id) or die(DB\dbQueryError());
                }
            } elseif (!empty($preview['html'])) {
                echo $preview['html'];
            }
            // $dbNode = new TreeNode\Dbnode();
            // echo '<!-- NodeName:'.$dbNode->getName($id).' -->';
        }
        break;
    default:
        $o = new Objects();
        $preview = $o->getPreview($id);
        echo implode("\n", $preview);
        break;
}
if (empty($_GET['i'])) {
                $cores[$r['name']] = $db;
            }
        }
        $res2->close();
    }
}
$res->close();
if (empty($cores)) {
    echo "No cores with custom translations.\n";
} else {
    echo "Processing " . sizeof($cores) . " cores with custom translations:\n";
    foreach ($cores as $core => $db) {
        $CT = $T;
        $res = DB\dbQuery('SELECT *
            FROM ' . $db . '.translations
            WHERE `type` in (0,2)') or die(DB\dbQueryError());
        while ($r = $res->fetch_assoc()) {
            foreach ($languages as $l) {
                if (!empty($r[$l])) {
                    $CT[$l][] = "'" . $r['name'] . "':'" . addcslashes($r[$l], "'") . "'";
                }
            }
        }
        saveFiles($CT, $core . '_');
        echo '.';
    }
}
echo "\nDone";
/**
 * save translation array as files
 * @param  array &$T
    WHERE cron_id = $1';
DB\dbQuery($sql, array($cron_id, Util\jsonEncode($rez))) or die(DB\dbQueryError());
if (checkTikaService() == false) {
    startTikaService();
}
$where = 'skip_parsing = 0 and (parse_status is null)';
if (!empty($scriptOptions['all'])) {
    $where = 'skip_parsing = 0';
}
$sql = 'SELECT id
    ,path
    ,`type`
    ,pages
FROM files_content
WHERE ' . $where;
$res = DB\dbQuery($sql) or die(DB\dbQueryError());
//and name like \'%.pdf\'
while ($r = $res->fetch_assoc()) {
    $filename = Config::get('files_dir') . $r['path'] . DIRECTORY_SEPARATOR . $r['id'];
    echo "\nFile: {$filename} (" . $r['type'] . ") ";
    if (file_exists($filename)) {
        $skip_parsing = 0;
        $pages = $r['pages'];
        if (substr($r['type'], 0, 5) != 'image') {
            if (!file_exists($filename . '.gz')) {
                echo "\nnot image processing content ...";
                $tikaRez = getTikaResult($filename);
                if ($tikaRez !== false) {
                    file_put_contents($filename . '.zip', $tikaRez);
                    $text = getZipFileContent($filename . '.zip', '__TEXT__');
                    $text = mb_convert_encoding($text, mb_detect_encoding($text), 'UTF-8');