summaryrefslogtreecommitdiff
path: root/bin/reevotech/PropiedadObtener.php
blob: 938c7d92166fc881743006025e68bd62d37dbb49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
# ----
# Copyright (C) 2013-2020 - Reevo Project (http://reevo.org)
# License: Affero GPL version 3 - http://www.gnu.org/licenses/agpl.html
# ES: Este script recibe el nombre de una pagina e intenta obtener el valor las propiedades específicas.
# Algo como: php PropiedadObtener.php -d="Deployment" -t="Experiencia:Summerhill" -p="experiencia:lugar" -p="experiencia:lugar-pais"
# ----

$opciones = getopt('d:t:p:f:');

if ($opciones['d']) {
  $deployment = $opciones['d'];
} else {
  echo "Es necesario que definas el nombre del deployment con -d='ecoversities'\n";
  exit;
}

// error_reporting(0);
// Load all the stuff
require_once( __DIR__ . '/vendor/autoload.php' );
require_once( __DIR__ .'/../../etc/global_config-'.$deployment.'.php' );
#echo "Deployment URL: $wgServer \n";

// Log in to a wiki
$api = new \Mediawiki\Api\MediawikiApi( $wgServer .'/api.php' );
$api->login( new \Mediawiki\Api\ApiUser( $REEVO_WIKI_API_USER, $REEVO_WIKI_API_PASS ) );
$services = new \Mediawiki\Api\MediawikiFactory( $api );



if ($opciones['t']) {
  if ($opciones['p']) {
    $title = $opciones['t'];
    if (is_string($opciones['p'])) {
      $prop[] = $opciones['p'];
    } else {
      $prop = $opciones['p'];
    }
    foreach ($prop as $key => $value) {
      // $p = explode('|', $value);
      $propiedades[$value] = '';
    }
    $result = ObtenerPropiedades($title, $propiedades, $opciones, $services);
  } else {
    echo "Es necesario que definas al menos una propiedad para obtener con -p='propiedad|valor'\n";
    exit;
  }
} else {
  echo "Es necesario que definas el nombe de la pagina a revisar con -t='Pagina'\n";
  exit;
}

// Obtengo el nombre de la página como parámetro

function ObtenerPropiedades($title, $propiedades, $opciones, $services) {

  $page = $services->newPageGetter()->getFromTitle( $title );
  $pagecontent = $page->getRevisions()->getLatest();
  if (!$pagecontent) {
    echo "\n**** ERROR: No existe una página con el nombre '$title'\n\n\n";
    exit();
  } else {
    // echo "\n**** PROCESANDO: '$title' ****\n";
  }

  $pagecontent = $page->getRevisions()->getLatest()->getContent()->getData();

  // armo un array con las propiedades de SMW
  $extracto = preg_grep('/^\|/', explode("\n", $pagecontent));
  foreach ($extracto as $key => $value) {
    $data = str_replace('|','',$value);
    $data_limpia = explode('=', $data);
    $propiedades_previas[$data_limpia[0]] = $data_limpia[1];
  }

  foreach ($propiedades as $key => $value) {
    if (array_key_exists($key, $propiedades_previas)) {
      echo "$propiedades_previas[$key]\n";
    }
  }

}

function accessProtected($obj, $prop) {
  $reflection = new ReflectionClass($obj);
  $property = $reflection->getProperty($prop);
  $property->setAccessible(true);
  return $property->getValue($obj);
}

?>