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;
 }
 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');
         DB\commitTransaction();
     }
 }
Exemple #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);
 }
 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'];
 }
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());
        }
    }
}
Exemple #6
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);
    }
}
Exemple #7
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;
 }
 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();
 }
if (!$cd['success']) {
    echo "\nerror preparing cron\n";
    exit(1);
}
$last_action_sql = 'UPDATE crons
    SET last_action = CURRENT_TIMESTAMP
    WHERE cron_id = $1';
$solr = new Solr\Client();
try {
    $all = !empty($scriptOptions['all']);
    $nolimit = !empty($scriptOptions['nolimit']);
    if ($all) {
        //mark all tree nodes as updated
        DB\dbQuery('UPDATE tree SET updated = 1', $cron_id) or die('error updating tree nodes');
        DB\dbQuery($last_action_sql, $cron_id) or die('error updating crons last action');
        echo "updating tree\n";
        $solr->updateTree(array('all' => true, 'cron_id' => $cron_id, 'nolimit' => $nolimit));
        DB\dbQuery($last_action_sql, $cron_id) or die('error updating crons last action');
        echo "optimizing\n";
        $solr->optimize();
        DB\dbQuery($last_action_sql, $cron_id) or die('error updating crons last action');
    } else {
        $solr->updateTree(array('cron_id' => $cron_id, 'nolimit' => $nolimit));
    }
} catch (\Exception $e) {
    $msg = 'CaseBox cron execution exception (' . $coreName . "):<br />\n" . $e->getMessage() . "<br />\n" . $e->getTraceAsString();
    echo $msg;
    System::notifyAdmin('CaseBox cron execution exception (' . $coreName . ')', $msg);
}
unset($solr);
// closeCron($cron_id);
Exemple #10
0
            echo '&#160';
        } 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 ($r2['count'] > 0) {
                $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
            $skip_parsing = 1;
        }
        DB\dbQuery('UPDATE files_content
            SET parse_status = 1
                ,pages = $2
                ,skip_parsing = $3
            WHERE id = $1', array($r['id'], $pages, $skip_parsing)) or die('error2');
        $rez['Processed'] = $rez['Processed'] + 1;
        $rez['Processed List'][] = $filename;
    } else {
        echo " - Not found.";
        $rez['Not found'] = $rez['Not found'] + 1;
        $rez['Not found List'][] = $filename;
    }
    DB\dbQuery('UPDATE crons
        SET last_action = CURRENT_TIMESTAMP
        WHERE cron_id = $1', $cron_id) or die('error updating crons last action');
    echo '.';
}
$res->close();
$rez['Total'] = $rez['Processed'] + $rez['Not found'];
// closeCron($cron_id, Util\jsonEncode($rez));
// Solr\Client::runCron();
function checkTikaService()
{
    $rez = true;
    // Create a curl handle to a non-existing location
    $ch = curl_init('http://127.0.0.1:9998/tika');
    // Execute
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);