On change le fonctionnement :
* on n'utilise plus spip_blocklogs_liens * on ajoute à la place id_objet / objet à spip_blocklogs * on passe en cle primaire : id_blocklog, id_objet, objet => comme cela, c'est restrictif mais c'est comme ca que cela doit fonctionner
This commit is contained in:
parent
8902d8ce92
commit
107f1d8b53
5 changed files with 35 additions and 57 deletions
|
@ -47,45 +47,20 @@ function blocklog_declarer_tables_objets_sql($tables) {
|
|||
'principale' => 'oui',
|
||||
'field'=> array(
|
||||
'id_blocklog' => 'bigint(21) NOT NULL',
|
||||
'id_objet' => 'bigint(21) DEFAULT "0" NOT NULL',
|
||||
'objet' => 'VARCHAR(25) DEFAULT "" NOT NULL',
|
||||
'num' => 'bigint(21) NOT NULL DEFAULT 0',
|
||||
'blockchaine' => 'text NOT NULL DEFAULT ""',
|
||||
'chaine' => 'text NOT NULL DEFAULT ""',
|
||||
'maj' => 'TIMESTAMP'
|
||||
),
|
||||
'key' => array(
|
||||
'PRIMARY KEY' => 'id_blocklog',
|
||||
'PRIMARY KEY' => 'id_blocklog,id_objet,objet',
|
||||
'KEY id_blocklog' => 'id_blocklog',
|
||||
'KEY id_objet' => 'id_objet',
|
||||
'KEY objet' => 'objet'
|
||||
),
|
||||
|
||||
'champs_editables' => array('num', 'blockchaine', 'chaine'),
|
||||
'tables_jointures' => array('spip_blocklogs_liens'),
|
||||
);
|
||||
|
||||
return $tables;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Déclaration des tables secondaires (liaisons)
|
||||
*
|
||||
* @pipeline declarer_tables_auxiliaires
|
||||
* @param array $tables
|
||||
* Description des tables
|
||||
* @return array
|
||||
* Description complétée des tables
|
||||
*/
|
||||
function blocklog_declarer_tables_auxiliaires($tables) {
|
||||
|
||||
$tables['spip_blocklogs_liens'] = array(
|
||||
'field' => array(
|
||||
'id_blocklog' => 'bigint(21) DEFAULT "0" NOT NULL',
|
||||
'id_objet' => 'bigint(21) DEFAULT "0" NOT NULL',
|
||||
'objet' => 'VARCHAR(25) DEFAULT "" NOT NULL',
|
||||
'vu' => 'VARCHAR(6) DEFAULT "non" NOT NULL',
|
||||
),
|
||||
'key' => array(
|
||||
'PRIMARY KEY' => 'id_blocklog,id_objet,objet',
|
||||
'KEY id_blocklog' => 'id_blocklog',
|
||||
)
|
||||
'champs_editables' => array('num', 'blockchaine', 'chaine','id_objet', 'objet'),
|
||||
);
|
||||
|
||||
return $tables;
|
||||
|
|
|
@ -26,7 +26,8 @@ if (!defined('_ECRIRE_INC_VERSION')) {
|
|||
function blocklog_upgrade($nom_meta_base_version, $version_cible) {
|
||||
$maj = array();
|
||||
|
||||
$maj['create'] = array(array('maj_tables', array('spip_blocklogs', 'spip_blocklogs_liens')));
|
||||
$maj['create'] = array(array('maj_tables', array('spip_blocklogs')));
|
||||
$maj['1.0.1'] = array(array('maj_tables', array('spip_blocklogs')));
|
||||
|
||||
include_spip('base/upgrade');
|
||||
maj_plugin($nom_meta_base_version, $version_cible, $maj);
|
||||
|
|
|
@ -18,15 +18,13 @@ function trouver_blocklog($id_objet, $objet, $id = false){
|
|||
|
||||
if ($r == null) {
|
||||
$from = array(
|
||||
'spip_blocklogs as B',
|
||||
'spip_blocklogs_liens as L'
|
||||
'spip_blocklogs',
|
||||
);
|
||||
$where = array(
|
||||
'L.id_objet='.intval($id_objet),
|
||||
'L.objet='.sql_quote($objet),
|
||||
'L.id_blocklog=B.id_blocklog'
|
||||
'id_objet='.intval($id_objet),
|
||||
'objet='.sql_quote($objet),
|
||||
);
|
||||
$r = sql_fetsel('B.id_blocklog, B.blockchaine, B.chaine', $from, $where, '', 'B.id_blocklog DESC', 1);
|
||||
$r = sql_fetsel('id_blocklog, blockchaine, chaine', $from, $where);
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
|
@ -40,8 +38,14 @@ function trouver_blocklog($id_objet, $objet, $id = false){
|
|||
function blocklog_verifier_blockchaine($id_objet, $objet){
|
||||
if (intval($id_objet) and $objet) {
|
||||
$r = trouver_blocklog($id_objet, $objet, true);
|
||||
$id_blocklog_pre = intval($r['id_blocklog']) - 1;
|
||||
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', 'id_blocklog='.intval($id_blocklog_pre));
|
||||
|
||||
$where = array(
|
||||
'objet='.sql_quote($objet),
|
||||
'id_blocklog<'.intval($r['id_blocklog'])
|
||||
);
|
||||
|
||||
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where, 'id_blocklog DESC', 1);
|
||||
|
||||
|
||||
if (! defined("_BLOCKLOG_ALGO")) {
|
||||
define("_BLOCKLOG_ALGO", 'sha256');
|
||||
|
|
|
@ -44,13 +44,18 @@ function inc_blocklog_dist($objet, $id_objet = 0, $num = 0, $chaine = '') {
|
|||
$chaine = hash(_BLOCKLOG_ALGO, $chaine);
|
||||
|
||||
|
||||
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs',1,'', 'id_blocklog DESC', '1');
|
||||
$where = array(
|
||||
'objet='.sql_quote($objet)
|
||||
);
|
||||
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where,'', 'id_blocklog DESC', '1');
|
||||
|
||||
$blockchaine .= "|" . $chaine;
|
||||
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
||||
|
||||
|
||||
$set = array (
|
||||
'objet' => $objet,
|
||||
'id_objet' => intval($id_objet),
|
||||
'blockchaine' => $blockchaine,
|
||||
'chaine' => $chaine,
|
||||
'num' => intval($num)
|
||||
|
@ -62,15 +67,11 @@ function inc_blocklog_dist($objet, $id_objet = 0, $num = 0, $chaine = '') {
|
|||
}
|
||||
|
||||
include_spip('action/editer_objet');
|
||||
$id_blocklog = objet_inserer("blocklog");
|
||||
objet_modifier("blocklog", $id_blocklog, $set);
|
||||
$set['id_blocklog'] = $id_blocklog;
|
||||
set_request('id_auteur', null);
|
||||
$r = objet_inserer("blocklog", null, $set);
|
||||
if (!$r) {
|
||||
spip_log("la blockchaine pour $objet / $id_objet existe deja", 'blocklog'._LOG_ERREUR);
|
||||
}
|
||||
|
||||
|
||||
include_spip('action/editer_liens');
|
||||
$objets_source = array("blocklog"=>$id_blocklog);
|
||||
$objets_lies = array($objet => $id_objet);
|
||||
objet_associer($objets_source, $objets_lies);
|
||||
|
||||
return $set;
|
||||
return $r;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<paquet
|
||||
prefix="blocklog"
|
||||
categorie="outil"
|
||||
version="1.0.0"
|
||||
version="1.1.0"
|
||||
etat="dev"
|
||||
compatibilite="[3.2.0;3.3.*]"
|
||||
logo="prive/themes/spip/images/blocklog-64.png"
|
||||
documentation=""
|
||||
schema="1.0.0"
|
||||
schema="1.0.1"
|
||||
>
|
||||
|
||||
<nom>Block Log</nom>
|
||||
|
@ -15,14 +15,11 @@
|
|||
<credit lien="https://gamuza.fr">Logo : tofulm</credit>
|
||||
|
||||
<licence>GNU/GPL</licence>
|
||||
<!--<necessite nom="saisies" compatibilite="[3.0.0;]" />-->
|
||||
|
||||
|
||||
<pipeline nom="autoriser" inclure="blocklog_autorisations.php" />
|
||||
|
||||
<pipeline nom="declarer_tables_objets_sql" inclure="base/blocklog.php" />
|
||||
<pipeline nom="declarer_tables_interfaces" inclure="base/blocklog.php" />
|
||||
<pipeline nom="declarer_tables_auxiliaires" inclure="base/blocklog.php" />
|
||||
<pipeline nom="optimiser_base_disparus" inclure="blocklog_pipelines.php" />
|
||||
|
||||
</paquet>
|
||||
|
|
Loading…
Add table
Reference in a new issue