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',
|
'principale' => 'oui',
|
||||||
'field'=> array(
|
'field'=> array(
|
||||||
'id_blocklog' => 'bigint(21) NOT NULL',
|
'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',
|
'num' => 'bigint(21) NOT NULL DEFAULT 0',
|
||||||
'blockchaine' => 'text NOT NULL DEFAULT ""',
|
'blockchaine' => 'text NOT NULL DEFAULT ""',
|
||||||
'chaine' => 'text NOT NULL DEFAULT ""',
|
'chaine' => 'text NOT NULL DEFAULT ""',
|
||||||
'maj' => 'TIMESTAMP'
|
'maj' => 'TIMESTAMP'
|
||||||
),
|
),
|
||||||
'key' => array(
|
'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','id_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',
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $tables;
|
return $tables;
|
||||||
|
|
|
@ -26,7 +26,8 @@ if (!defined('_ECRIRE_INC_VERSION')) {
|
||||||
function blocklog_upgrade($nom_meta_base_version, $version_cible) {
|
function blocklog_upgrade($nom_meta_base_version, $version_cible) {
|
||||||
$maj = array();
|
$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');
|
include_spip('base/upgrade');
|
||||||
maj_plugin($nom_meta_base_version, $version_cible, $maj);
|
maj_plugin($nom_meta_base_version, $version_cible, $maj);
|
||||||
|
|
|
@ -18,15 +18,13 @@ function trouver_blocklog($id_objet, $objet, $id = false){
|
||||||
|
|
||||||
if ($r == null) {
|
if ($r == null) {
|
||||||
$from = array(
|
$from = array(
|
||||||
'spip_blocklogs as B',
|
'spip_blocklogs',
|
||||||
'spip_blocklogs_liens as L'
|
|
||||||
);
|
);
|
||||||
$where = array(
|
$where = array(
|
||||||
'L.id_objet='.intval($id_objet),
|
'id_objet='.intval($id_objet),
|
||||||
'L.objet='.sql_quote($objet),
|
'objet='.sql_quote($objet),
|
||||||
'L.id_blocklog=B.id_blocklog'
|
|
||||||
);
|
);
|
||||||
$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) {
|
if ($id) {
|
||||||
|
@ -40,8 +38,14 @@ function trouver_blocklog($id_objet, $objet, $id = false){
|
||||||
function blocklog_verifier_blockchaine($id_objet, $objet){
|
function blocklog_verifier_blockchaine($id_objet, $objet){
|
||||||
if (intval($id_objet) and $objet) {
|
if (intval($id_objet) and $objet) {
|
||||||
$r = trouver_blocklog($id_objet, $objet, true);
|
$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")) {
|
if (! defined("_BLOCKLOG_ALGO")) {
|
||||||
define("_BLOCKLOG_ALGO", 'sha256');
|
define("_BLOCKLOG_ALGO", 'sha256');
|
||||||
|
|
|
@ -44,13 +44,18 @@ function inc_blocklog_dist($objet, $id_objet = 0, $num = 0, $chaine = '') {
|
||||||
$chaine = hash(_BLOCKLOG_ALGO, $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 .= "|" . $chaine;
|
||||||
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
||||||
|
|
||||||
|
|
||||||
$set = array (
|
$set = array (
|
||||||
|
'objet' => $objet,
|
||||||
|
'id_objet' => intval($id_objet),
|
||||||
'blockchaine' => $blockchaine,
|
'blockchaine' => $blockchaine,
|
||||||
'chaine' => $chaine,
|
'chaine' => $chaine,
|
||||||
'num' => intval($num)
|
'num' => intval($num)
|
||||||
|
@ -62,15 +67,11 @@ function inc_blocklog_dist($objet, $id_objet = 0, $num = 0, $chaine = '') {
|
||||||
}
|
}
|
||||||
|
|
||||||
include_spip('action/editer_objet');
|
include_spip('action/editer_objet');
|
||||||
$id_blocklog = objet_inserer("blocklog");
|
set_request('id_auteur', null);
|
||||||
objet_modifier("blocklog", $id_blocklog, $set);
|
$r = objet_inserer("blocklog", null, $set);
|
||||||
$set['id_blocklog'] = $id_blocklog;
|
if (!$r) {
|
||||||
|
spip_log("la blockchaine pour $objet / $id_objet existe deja", 'blocklog'._LOG_ERREUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $r;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<paquet
|
<paquet
|
||||||
prefix="blocklog"
|
prefix="blocklog"
|
||||||
categorie="outil"
|
categorie="outil"
|
||||||
version="1.0.0"
|
version="1.1.0"
|
||||||
etat="dev"
|
etat="dev"
|
||||||
compatibilite="[3.2.0;3.3.*]"
|
compatibilite="[3.2.0;3.3.*]"
|
||||||
logo="prive/themes/spip/images/blocklog-64.png"
|
logo="prive/themes/spip/images/blocklog-64.png"
|
||||||
documentation=""
|
documentation=""
|
||||||
schema="1.0.0"
|
schema="1.0.1"
|
||||||
>
|
>
|
||||||
|
|
||||||
<nom>Block Log</nom>
|
<nom>Block Log</nom>
|
||||||
|
@ -15,14 +15,11 @@
|
||||||
<credit lien="https://gamuza.fr">Logo : tofulm</credit>
|
<credit lien="https://gamuza.fr">Logo : tofulm</credit>
|
||||||
|
|
||||||
<licence>GNU/GPL</licence>
|
<licence>GNU/GPL</licence>
|
||||||
<!--<necessite nom="saisies" compatibilite="[3.0.0;]" />-->
|
|
||||||
|
|
||||||
|
|
||||||
<pipeline nom="autoriser" inclure="blocklog_autorisations.php" />
|
<pipeline nom="autoriser" inclure="blocklog_autorisations.php" />
|
||||||
|
|
||||||
<pipeline nom="declarer_tables_objets_sql" inclure="base/blocklog.php" />
|
<pipeline nom="declarer_tables_objets_sql" inclure="base/blocklog.php" />
|
||||||
<pipeline nom="declarer_tables_interfaces" 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" />
|
<pipeline nom="optimiser_base_disparus" inclure="blocklog_pipelines.php" />
|
||||||
|
|
||||||
</paquet>
|
</paquet>
|
||||||
|
|
Loading…
Add table
Reference in a new issue