DatamigrationController.php 190 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
	
/* Author Bouboule (clement.damiens@gmail.com)
* Controller to update data with all bash done on db
* Documentation done before each function and in communecter/docs/devlog.md
*
*
*/
class DatamigrationController extends CommunecterController {
  
  protected function beforeAction($action) {
	return parent::beforeAction($action);
  }

  public function actionKnowsToFollows(){
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		 $persons=PHDB::find(Person::COLLECTION);
		foreach($persons as $key => $data){
			if(isset($data["links"]["followers"]) || isset($data["links"]["follows"])){
				$followers=array();
				$follows=array();
				if(isset($data["links"]["followers"]) && !empty($data["links"]["followers"])){
					$followers=$data["links"]["followers"];
				}
				if(isset($data["links"]["follows"]) && !empty($data["links"]["follows"])){
					$follows=$data["links"]["follows"];
				}
				PHDB::update(Person::COLLECTION,
					array("_id" => $data["_id"]) , 
					array('$unset' => array("links.followers" => ""))
				);
				PHDB::update(Person::COLLECTION,
					array("_id" => $data["_id"]) , 
					array('$unset' => array("links.follows" => ""))
				);
				if(!empty($followers)){
					//foreach ($followers as $uid => $e){	
38
						PHDB::update(Person::COLLECTION,
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
							array("_id" => $data["_id"]) , 
							array('$set' => array("links.follows" => $followers))
							);
					//}
				}
				if (!empty($follows)){
					foreach ($follows as $uid => $e){	
						if($e["type"]=="citoyens"){
						PHDB::update(Person::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("links.followers.".$uid => $e))
							);
						} else {
							PHDB::update(Person::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("links.follows.".$uid => $e))
							);
						}
57
58
					}
				}
59
60
61
62
				$newLinks=PHDB::findOneById(Person::COLLECTION ,$data["_id"]);
				echo "<br/>/////////////////////////// NEW LINK ////////////////////<br/>";
				print_r($newLinks["links"]);
				}	
63
			}
64
	}
65
66
67
68
69
  }
	//Refactor permettant de mettre la size des doc en bytes type string 
	// Pas encore Passez en prod et dev
	// A lancer une fois pour que ce soit stocké en int32 ou int64
	public function actionChangeSizeDocumentToBytesNumber(){
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$document=PHDB::find(Document::COLLECTION);
			$nbDoc=count($document);
			echo "Nombre de documents appelés : ".$nbDoc;
			$i=0;
			foreach($document as $key => $data){
				if(@$data["size"]){
					$size="";
					echo "<br/>".$data["_id"]."//".$data["size"]."///";
					echo gettype($data["size"]);
					if(gettype($data["size"])=="double"){
						$size = (int)$data["size"];
					}
					if (strstr($data["size"], 'M', true)){
						$size=((float)$data["size"])*1048576;
					} 
					else if(strstr($data["size"], 'K', true)){
						$size = (float)($data["size"])*1024;
					}
					$i++;
					if(@$size && !empty($size)){
						echo "new size : ".$size;
						PHDB::update(Document::COLLECTION,
								array("_id" => $data["_id"]) , 
								array('$set' => array("size" => (int)$size))	
			
						);
					}	
98
99
				}
			}
100
			echo "</br>Nombre de documents traités pour la size : ".$i; 
101
102
103
104
105
106
107
108
		}
	}
	//Refactor of contentKey
	//@param string contentKey type type.view.contentKey become contentKey
	//!!!!!!!!!!!! CAREFULLY THIS METHOD IS FOR COMMUNECTER AND NOT FOR GRANDDIR !!!!!!!!!!!!!!!!!//////
	// For the moment refactorContentKey change all contentKey to profil 
	// Function need to be change with an explode and $contentKey = $explode[2] for granddir
	public function actionRefactorContentKey(){
109
110
111
112
113
114
115
116
117
118
119
120
121
122
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$document=PHDB::find(Document::COLLECTION);
			$nbDoc=count($document);
			echo "Nombre de documents appelés : ".$nbDoc;
			$i=0;
			foreach($document as $key => $data){
				if(strstr($data["contentKey"],'.')){
					echo $data["contentKey"]."<br/>";
					PHDB::update(Document::COLLECTION,
						array("_id" => $data["_id"]) , 
						array('$set' => array("contentKey" => "profil"))	
					);
					$i++;
				}
123
			}
124
			echo "</br>Nombre de documents concerné par le refactor : ".$i;  
125
126
127
128
129
130
131
		}
	}
	// Washing of docmuent
	// Wash data with array in params @size which could be string
	// Wash data with no type or no id, represent the target of the document
	// Wash data with no contentKey
	public function actionWashIncorrectAndOldDataDocument(){
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$document=PHDB::find(Document::COLLECTION);
			$nbDoc=count($document);
			echo "Nombre de documents appelés : ".$nbDoc;
			$nbDocSizeIsArray=0;
			$nbDocNoTypeOrNoId=0;
			$nbDocNoContentKey=0;
			foreach($document as $key => $data){
				if(gettype($data["size"])=="array"){
					echo "<br/>//////// This document content an array for size : <br/>";
					print_r($data);
					PHDB::remove(Document::COLLECTION,array("_id" => $data["_id"]));
					$nbDocSizeIsArray++;
				}
				if( !@$data["type"] || !@$data["id"] || empty($data["type"]) || empty($data["id"])){
					echo "<br/>//////// This document doesn't content any type or id : <br/>";
					print_r($data);
					PHDB::remove(Document::COLLECTION,array("_id" => $data["_id"]));
					$nbDocNoTypeOrNoId++;
				}
				if( !@$data["contentKey"] || empty($data["contentKey"])){
					echo "<br/>//////// This document doesn't content any contentKey : <br/>";
					print_r($data);
					PHDB::remove(Document::COLLECTION,array("_id" => $data["_id"]));
					$nbDocNoContentKey++;
				}
158
			}
159
160
161
			echo "</br>//////// <br/>Nombre de documents sans type ou id: ".$nbDocNoTypeOrNoId; 
			echo "</br>//////// <br/>Nombre de documents sans contentKey: ".$nbDocNoContentKey;
			echo "</br>//////// <br/>Nombre de documents avec size comme array: ".$nbDocSizeIsArray;  
162
163
164
165
166
167
168
169
170
		}
	}
	/* 
	* Upload image from media type url content
	*	Condition: if not from communevent
	*	News uploadNewsImage
	*   Update link @param media.content.image in news collection
	*/
	public function actionUploadImageFromMediaUrlNews(){
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  $news=PHDB::find(News::COLLECTION);
		  $i=0;
		  foreach($news as $key => $data){
			  if(@$data["media"] && @$data["media"]["content"] && @$data["media"]["content"]["image"] && !@$data["media"]["content"]["imageId"]){
				  	if (strstr($data["media"]["content"]["image"],"upload/communecter/news/")==false){
				  		sleep(1);
				  		echo $data["media"]["content"]["image"]."<br/>";
				  		$returnUrl=News::uploadNewsImage($data["media"]["content"]["image"],$data["media"]["content"]["imageSize"],$data["author"]);
				  		$newUrl= Yii::app()->baseUrl."/".$returnUrl;
				  		echo 'Nouvelle url <br/>'.$newUrl."<br/>/////////////<br/>";
				  		PHDB::update(News::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("media.content.image" => $newUrl))			
						);
				  		$i++;
			 		}
				}
189
			}
190
			echo "nombre de news avec images provenant d'un autre site////////////// ".$i;
191
192
193
		}
	}
	/* 
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
	* update type french instead of key
	*/
	public function actionUpdateTypeRessources(){
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  $ress=PHDB::find(Ressource::COLLECTION);
		  $i=0;
		  foreach($ress as $key => $data){
			  $label="";
			  if(@$data["type"]=="compétence")
			  		$label="competence";
			  else if(@$data["type"]=="matériel")
			  	$label="material";
			  if($label!=""){
				  		echo '=>Ressoruce id : '.$key."<br/>last type : ".$data["type"]."///// New type : ".$label."<br/>";
				  		PHDB::update(Ressource::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("type" => $label))			
						);
				  		$i++;
			 		}
			}
			echo "nombre de ressource updaté type to clé////////////// ".$i;
		}
	}
	/* 
219
220
221
222
223
224
	* Scope public in news not well formated (ancient news)
	*	Condition: if not from communevent
	*	News uploadNewsImage
	*   Update link @param media.content.image in news collection
	*/
	public function actionBashRepareBulshit(){
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  $news=PHDB::find(News::COLLECTION);
		  $nbNews=count($news);
		  $i=0;
		  $newsWrong=0;
		  $nbNewsGood=0;
		  foreach($news as $key => $data){
			  	if($data["scope"]["type"]=="public"){
				  	if(!@$data["scope"]["cities"][0]){
					  	$newScopeArray=array("type"=>"public","cities"=>array());
					  	if($data["type"]=="activityStream"){
						  	$object=PHDB::findOne($data["object"]["objectType"],array("_id"=>new MongoId($data["object"]["id"])));
								$newScopeArray["cities"][0]["codeInsee"]=$object["address"]["codeInsee"];
								$newScopeArray["cities"][0]["postalCode"]=$object["address"]["postalCode"];
								$newScopeArray["cities"][0]["geo"]=$object["geo"];
								PHDB::update(News::COLLECTION,
											array("_id" => $data["_id"]) , 
											array('$set' => array("scope" => $newScopeArray)	
							));
							$newsWrong++;
					  	}
					  	/*else{
							if($data["target"]["type"]=="pixels"){
								$author=PHDB::findOne(Person::COLLECTION,array("_id"=>new MongoId($data["author"])));
								$newScopeArray["cities"][0]["codeInsee"]=$author["address"]["codeInsee"];
								$newScopeArray["cities"][0]["postalCode"]=$author["address"]["postalCode"];
								$newScopeArray["cities"][0]["geo"]=$author["geo"];
							}else {
								$target=PHDB::findOne($data["target"]["type"],array("_id"=>new MongoId($data["target"]["id"])));
								$newScopeArray["cities"][0]["codeInsee"]=$target["address"]["codeInsee"];
								$newScopeArray["cities"][0]["postalCode"]=$target["address"]["postalCode"];
								$newScopeArray["cities"][0]["geo"]=$target["geo"];
							}
258
							PHDB::update(News::COLLECTION,
259
260
261
262
											array("_id" => $data["_id"]) , 
											array('$set' => array("scope" => $newScopeArray)	
							));
						}*/
263

264
265
266
267
					}
					else{
						$nbNewsGood++;
					}
268
269
				}
			}
270
271
272
			echo "nombre total de news: ".$nbNews."news";
			echo "nombre de news mauvaise: ".$newsWrong."news";
			echo "nombre de news good: ".$nbNewsGood."news";
273
274
275
276
277
278
279
280
281
		}
	}
	/* 
	* Scope public in news not well formated (ancient news)
	*	Condition: if not from communevent
	*	News uploadNewsImage
	*   Update link @param media.content.image in news collection
	*/
	public function actionBashNewsWrongScope(){
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  $news=PHDB::find(News::COLLECTION);
		  $i=0;
		  $nbCityCodeInsee=0;
		  $nbCityName=0;
		  $nbtodelete=0;
		  $nbCityNotFindName=0;
		  foreach($news as $key => $data){
			  if($data["scope"]["type"]=="public"){
				  if(@$data["scope"]["cities"]){
					  	$newScopeArray=array("type"=>"public","cities"=>array());
					  	if(@$data["scope"]["cities"][0] && gettype($data["scope"]["cities"][0])=="string"){

						  	  	echo "<br/>////////id News: ".$key. "/////////";				  	  						  	print_r($data["scope"]);
						  	foreach($data["scope"]["cities"] as $value){
							  	if(is_numeric($value)){
								  	echo "<br/>ici numérique:".$value;
299
300
301
302
303
304
305
306
307
								  	$city=PHDB::findOne(City::COLLECTION, array("insee" => $value));
								  	$newScopeArray["cities"][0]["codeInsee"]=$value;
								  	$newScopeArray["cities"][0]["postalCode"]=$city["postalCodes"][0]["postalCode"];
								  	if(@$data["geo"]){
									  	$newScopeArray["cities"][0]["geo"]=$data["geo"];
								  	}else{
									  	$newScopeArray["cities"][0]["geo"]=$city["geo"];
								  	}
								  	$nbCityCodeInsee++;
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
							  	} else {
								  	echo "<br/>ici non numérique mais string: ".$value;
								  	if($value=="LA RIVIERE"){
									  	$newScopeArray["cities"][0]["codeInsee"]="97414";
									  	$newScopeArray["cities"][0]["postalCode"]="97421";
									  	$newScopeArray["cities"][0]["geo"]=array('@type' => 'GeoCoordinates','latitude'=>'-21.25833300','longitude'=>'55.44166700');
									  	$nbCityName++;
								  	}
								  	else{
								  	$city = PHDB::findOne(City::COLLECTION, array("alternateName" =>$value));
								  		if(!empty($city)){
									  		$newScopeArray["cities"][0]["codeInsee"]=$city["insee"];
									  		$newScopeArray["cities"][0]["postalCode"]=$city["postalCodes"][0]["postalCode"];
									  		$newScopeArray["cities"][0]["geo"]=$city["geo"];
								  		$nbCityName++;
								  		}else{
								  			echo "ici";
								  			$newScopeArray["cities"][0]="wrong";
								  			$nbCityNotFindName++;	
								  		}
								  	}
							  	}
							  	echo "<br/>===>News array scope: ///<br/>";
331
								print_r($newScopeArray);
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
							  	echo "<br/>";
						  	}
						  	PHDB::update(News::COLLECTION,
								array("_id" => $data["_id"]) , 
								array('$set' => array("scope" => $newScopeArray)			
							));
							$i++;
					  	} else {
						  	if (!@$data["scope"]["cities"][0])
							{
							 	echo "<br/>/////////////////// PAS DE 00000 ////////////////////<br/>";
							 	$insee=false;
							 	foreach($data["scope"]["cities"] as $value){
								 	if(is_numeric($value)){
									 	$insee=$value;
								 	}	
							 	}
							 	if($insee){
							 		echo "<br/>ici numérique:".$value;
									  	$city=PHDB::findOne(City::COLLECTION, array("insee" => $value));
									  	$newScopeArray["cities"][0]["codeInsee"]=$value;
									  	$newScopeArray["cities"][0]["postalCode"]=$city["postalCodes"][0]["postalCode"];
									  	if(@$data["geo"]){
										  	$newScopeArray["cities"][0]["geo"]=$data["geo"];
									  	}else{
										  	$newScopeArray["cities"][0]["geo"]=$city["geo"];
									  	}
									  	$nbCityCodeInsee++;
									  	$i++;
									print_r($newScopeArray);
									echo "<br/>";
									PHDB::update(News::COLLECTION,
										array("_id" => $data["_id"]) , 
										array('$set' => array("scope" => $newScopeArray)			
									));
							 	}
							}
							
					  	}
				  } 
				  else{
					  echo "<br/>////news to delete avec wrong scope/////<br/>";
					  print_r($data["scope"]);
					  $nbtodelete++;
					  echo "<br/>";
					   PHDB::remove(News::COLLECTION, array("_id"=>$data["_id"]));
					   $i++;
				  }
			}
			}
			echo "nombre de news avec insee enregistré: ".$nbCityCodeInsee."news";
			echo "nombre de news avec name enregistré: ".$nbCityName."news";
			echo "nombre de news à supprimer: ".$nbtodelete."news";
			echo "nombre de news avec city non trouvé: ".$nbCityNotFindName."news";
			echo "nombre de news avec data publique not well formated: ".$i."news";
387
388
389
390
391
392
393
394
		}
	}
	/* First refactor à faire sur communecter.org 
	* Remove all id and type in and object target.id, target.type
	*	=> Modify target type city to target.id=author, target.type=Person::COLLECTION
	*	=> Add @params type string "news" OR "activityStream"
	*/
	public function actionRefactorNews(){
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  $news=PHDB::find(News::COLLECTION);
		  $i=0;
		  foreach($news as $key => $data){
			  if(@$data["type"] && $data["type"]!="activityStream"){
				  //print_r($data["_id"]);
				  // add une target au lieu de id et type et type devient news
				  // pour les type city => la target devient l'auteur
				  if($data["type"]!="news"){
					  if(@$data["id"]){
					  	$parentType=$data["type"];
					  	$parentId=$data["id"];
					  	if($parentType=="city"){
						  $parentType=Person::COLLECTION;
						  $parentId=$data["author"];
					  	}
					  PHDB::update(News::COLLECTION,
412
						array("_id" => $data["_id"]) , 
413
414
						array('$set' => array("target.type" => $parentType,"target.id"=>$parentId, "type" => "news"),'$unset' => array("id"=>""))			
						);
415
					$i++;
416
417
418
419
420
421
422
					} else if($data["type"]=="pixels"){
						PHDB::update(News::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("target.type" => "pixels","target.id"=>"", "type" => "news"),'$unset' => array("id"=>""))			
						);
						$i++;
					}
423
				}
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
				 // print_r($data);
			  }
			  if(@$data["type"] && $data["type"]=="activityStream"){
				  if(@$data["target"]){
				 	 //adapter le vocubulaire de target pour qu'il soit comment au news type "news"
				  	// passe target.objectType à target.type
					 $parentType=$data["target"]["objectType"];
					 // $parentId=$data["id"];
						  PHDB::update(News::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("target.type" => $parentType),'$unset' => array("target.objectType"=>""))			
						);
									$i++;
					}
			  }
439
			}
440
			echo "nombre de news ////////////// ".$i;
441
442
443
444
445
		}
	}

   // Second refactor à faire sur communecter.org qui permet de netoyer les news sans scope
  public function actionWashingNewsNoScopeType(){
446
447
448
449
450
451
452
453
454
	  if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
	  $news=PHDB::find(News::COLLECTION);
	  foreach($news as $key => $data){
			  if(!@$data["scope"]["type"]){
			  print_r($data);
			  PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
			  	
			}
			}
455
456
		}
	}
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
	
	// Second refactor à faire sur communecter.org qui permet de netoyer les news sans scope
 	public function actionUpdateTypeInCollectionsLinkToClassifieds(){
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
	  		echo "--------------------------------------------------------------------------------<br/>".
	  			"---------------------------------------DOCUMENTS-------------------------------<br/>".
	  			"--------------------------------------------------------------------------------<br/>";
	  		
	  		$documents=PHDB::find(Document::COLLECTION,array('$or'=>array(array("type"=>"classified"), array("type"=>"ressources"))));
	  		$documentNb=0;
	  		foreach ($documents as $key => $value) {
	  			echo "Document modified :".$key."<br/>";
	  			echo "type:".$value["type"]." devient classifieds<br/>";
	  			$value["type"]="classifieds";
	  			$value["folder"]=preg_replace("/ressources/", "classifieds", $value["folder"]);
	  			$value["folder"]=preg_replace("/classified/", "classifieds", $value["folder"]);
	  			echo "folder:".$value["folder"]."<br/>";
	  			echo "---------------------------------------------------<br/>";
	  			PHDB::update(Document::COLLECTION,
					array("_id" => $value["_id"]) , 
					array('$set' => array("type" => $value["type"], "folder"=>$value["folder"]))			
				);
				$documentNb++;
	  		}
	  		echo "Nombre de documents modifier : ".$documentNb."<br/><br/><br/>";
	  		echo "--------------------------------------------------------------------------------<br/>".
	  			"------------------------------------NOTIFS--------------------------------------<br/>".
	  			"--------------------------------------------------------------------------------<br/>";
	  		$activityStream=PHDB::find(ActivityStream::COLLECTION,array("type"=>"notifications",'$or'=>array(array("target.type"=>"classified"), array("target.type"=>"ressources"))));
	  		$activityStreamNb=0;
	  		foreach ($activityStream as $key => $value) {
	  			echo "Notifs modified :".$key."<br/>";
	  			echo "type:".$value["target"]["type"]." devient classifieds<br/>";
	  			$targetType="classifieds";
	  			$set=array("target.type"=>"classifieds");
	  			if(@$value["notify"] && @$value["notify"]["url"]){
		  			$url=preg_replace("/ressources/", "classifieds", $value["notify"]["url"]);
		  			$url=preg_replace("/classified/", "classifieds", $value["notify"]["url"]);
		  			echo "notify.url:".$url."<br/>";
		  			$set["notify.url"]=$url;
	  			}
	  			print_r($set);
	  			echo "---------------------------------------------------<br/>";
	  			PHDB::update(ActivityStream::COLLECTION,
					array("_id" => $value["_id"]) , 
					array('$set' => $set)			
				);
				$activityStreamNb++;
	  		}
	  		echo "Nombre de notifications modifier : ".$activityStreamNb."<br/><br/><br/>";
	  		echo "--------------------------------------------------------------------------------<br/>".
	  			"---------------------------------COMMENTS------------------------------------------<br/>".
	  			"--------------------------------------------------------------------------------<br/>";
	  		$comments=PHDB::find(Comment::COLLECTION,array('$or'=>array(array("contextType"=>"classified"), array("contextType"=>"ressources"))));
	  		$commentsNb=0;
	  		foreach ($comments as $key => $value) {
	  			echo "Comment modified :".$key."<br/>";
	  			echo "contextType:".$value["contextType"]." devient classifieds<br/>";
	  			//$targetType="classifieds";
	  			$set=array("contextType"=>"classifieds");
	  			print_r($set);
	  			echo "---------------------------------------------------<br/>";
	  			PHDB::update(Comment::COLLECTION,
					array("_id" => $value["_id"]) , 
					array('$set' => $set)			
				);
				$commentsNb++;
	  		}
	  		echo "Nombre de comments modifier : ".$commentsNb."<br/><br/><br/>";
	  		echo "--------------------------------------------------------------------------------<br/>".
	  			"---------------------------------NEWS------------------------------------------<br/>".
	  			"--------------------------------------------------------------------------------<br/>";
	  		$news=PHDB::find(News::COLLECTION,array('$or'=>array(array("object.type"=>"classified"), array("object.type"=>"ressources"))));
	  		$newsNb=0;
	  		foreach ($news as $key => $value) {
	  			echo "News modified :".$key."<br/>";
	  			echo "contextType:".$value["object"]["type"]." devient classifieds<br/>";
	  			//$targetType="classifieds";
	  			$set=array("object.type"=>"classifieds");
	  			print_r($set);
	  			echo "---------------------------------------------------<br/>";
	  			PHDB::update(News::COLLECTION,
					array("_id" => $value["_id"]) , 
					array('$set' => $set)			
				);
				$newsNb++;
	  		}
	  		echo "Nombre de news modifier : ".$newsNb;
		}else
			echo "hi han dis l'ane";
	}
	// Refactor classifieds
  	public function actionUpdateDateInDB(){
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  	$classifieds=PHDB::find(Classified::COLLECTION);
		  	foreach($classifieds as $key => $v){
		  		PHDB::update(Classified::COLLECTION,
					array("_id" => $v["_id"]) , 
					array('$set' => array("modified"=>new MongoDate($v["modified"]["sec"])))			
				);
		  	}
Clément Damiens's avatar
Clément Damiens committed
558
		  	echo "done mon petit";
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
		}
	}
	// Refactor classifieds
  	public function actionUpdateLineInDB(){
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  	$classifieds=PHDB::find(Classified::COLLECTION);
		  	foreach($classifieds as $key => $v){
		  		if(is_array($v["updated"])){
		  			PHDB::update(Classified::COLLECTION,
					array("_id" => $v["_id"]) , 
					array('$set' => array("updated"=> $v["updated"]["sec"]))			
					);
		  		}
		  		/*PHDB::update(Classified::COLLECTION,
					array("_id" => $v["_id"]) , 
					array('$set' => array("updated"=> strtotime ($v["updated"]["sec"]), "created"=>strtotime ($v["created"]["sec"])))			
				);*/
		  	}
Clément Damiens's avatar
Clément Damiens committed
577
		  	echo "impressionnant";
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
		}
	}
	// Refactor classifieds
  	public function actionUpdateClassifiedAndMergeRessources(){
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  	$classifieds=PHDB::find(Classified::COLLECTION);
		  	$allClassifieds=[];
		  	foreach($classifieds as $key => $data){
		  		$data["_id"]=array('$oid'=>(string)$data["_id"]);
				if(@$data["section"]=="job"){
					$data["subtype"]=strtolower($data["type"]);
					$data["type"]="jobs";
					$data["section"]="offer";
					$data["category"]="joboffer";
					if(@$data["profilImageUrl"]) $data["profilImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilImageUrl"]);
					if(@$data["profilThumbImageUrl"]) $data["profilThumbImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilThumbImageUrl"]);
					if(@$data["profilMarkerImageUrl"]) $data["profilMarkerImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMarkerImageUrl"]);
					if(@$data["profilMediumImageUrl"]) $data["profilMediumImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMediumImageUrl"]);
				  	//print_r($data);
				  	//echo "----------------------------------------<br/><br/>";
				  	array_push($allClassifieds, $data);
				  	//PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
				} else if($data["section"]=="Vendre" || $data["section"]=="forsale"){
					//echo "Classified type classifieds (for sale) :".$key."<br/><br/>";
					$data["category"]=strtolower($data["type"]);
					$data["type"]="classifieds";
					$data["section"]="forsale";
					$data["subtype"]=strtolower(@$data["subtype"]);
					//print_r($data);
					if(@$data["profilImageUrl"]) $data["profilImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilImageUrl"]);
					if(@$data["profilThumbImageUrl"]) $data["profilThumbImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilThumbImageUrl"]);
					if(@$data["profilMarkerImageUrl"]) $data["profilMarkerImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMarkerImageUrl"]);
					if(@$data["profilMediumImageUrl"]) $data["profilMediumImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMediumImageUrl"]);
					array_push($allClassifieds, $data);
				  	//echo "----------------------------------------<br/><br/>";
				}else if($data["section"]=="Louer" || $data["section"]=="forrent"){
					//echo "Classified type classifieds (for rent) :".$key."<br/><br/>";
					$data["category"]=strtolower($data["type"]);
					$data["type"]="classifieds";
					$data["section"]="forrent";
					$data["subtype"]=strtolower(@$data["subtype"]);
					//print_r($data);
					if(@$data["profilImageUrl"]) $data["profilImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilImageUrl"]);
					if(@$data["profilThumbImageUrl"]) $data["profilThumbImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilThumbImageUrl"]);
					if(@$data["profilMarkerImageUrl"]) $data["profilMarkerImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMarkerImageUrl"]);
					if(@$data["profilMediumImageUrl"]) $data["profilMediumImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMediumImageUrl"]);
				  	
					array_push($allClassifieds, $data);
					//echo "----------------------------------------<br/><br/>";
				}else if($data["section"]=="Donner" || $data["section"]=="donation" || $data["section"]=="Partager" || $data["section"]=="sharing"){
					//echo "Classified type ressources (offer) :".$key."<br/><br/>";
					$data["category"]="isToImplemant";
					$data["subtype"]="isToImplemant";
					$data["type"]="ressources";
					$data["section"]="offer";
					if(@$data["profilImageUrl"]) $data["profilImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilImageUrl"]);
					if(@$data["profilThumbImageUrl"]) $data["profilThumbImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilThumbImageUrl"]);
					if(@$data["profilMarkerImageUrl"]) $data["profilMarkerImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMarkerImageUrl"]);
					if(@$data["profilMediumImageUrl"]) $data["profilMediumImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMediumImageUrl"]);
				  	
					if(@$data["devise"]) unset($data["devise"]);
					//print_r($data);
					array_push($allClassifieds, $data);
					//echo "----------------------------------------<br/><br/>";
				}else if($data["section"]=="lookingfor" || $data["section"]=="Besoin"){
					//echo "Classified type ressources (need) :".$key."<br/><br/>";
					$data["category"]="isToImplemant";
					$data["subtype"]="isToImplemant";
					$data["type"]="ressources";
					$data["section"]="need";
					if(@$data["devise"]) unset($data["devise"]);
					//print_r($data);
					if(@$data["profilImageUrl"]) $data["profilImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilImageUrl"]);
					if(@$data["profilThumbImageUrl"]) $data["profilThumbImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilThumbImageUrl"]);
					if(@$data["profilMarkerImageUrl"]) $data["profilMarkerImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMarkerImageUrl"]);
					if(@$data["profilMediumImageUrl"]) $data["profilMediumImageUrl"]=preg_replace("/classified/", "classifieds", $data["profilMediumImageUrl"]);
				  	
					array_push($allClassifieds, $data);
					//echo "----------------------------------------<br/><br/>";
				}
				echo json_encode($data);
			}
			$ressources=PHDB::find(Ressource::COLLECTION);
			foreach($ressources as $key => $data){
				$data["_id"]=array('$oid'=>(string)$data["_id"]);
				//echo "Classified type ressources :".$key."<br/><br/>";
				$data["category"]=$data["type"];
				$data["type"]="ressources";
				if(@$data["profilImageUrl"]) $data["profilImageUrl"]=preg_replace("/ressources/", "classifieds", $data["profilImageUrl"]);
				if(@$data["profilThumbImageUrl"]) $data["profilThumbImageUrl"]=preg_replace("/ressources/", "classifieds", $data["profilThumbImageUrl"]);
				if(@$data["profilMarkerImageUrl"]) $data["profilMarkerImageUrl"]=preg_replace("/ressources/", "classifieds", $data["profilMarkerImageUrl"]);
				if(@$data["profilMediumImageUrl"]) $data["profilMediumImageUrl"]=preg_replace("/ressources/", "classifieds", $data["profilMediumImageUrl"]);
				  	
			  	//print_r($data);
			  	//echo "----------------------------------------<br/><br/>";
			  	array_push($allClassifieds, $data);
Raph El's avatar
Modif    
Raph El committed
674
				// echo json_encode($data);
675
676
677
678
679
680
681
			}
			//echo "<br/><br/><br/><hr><hr/><h1>JSON CLASSIFIEDS GENERATE</h1><br/><br/><br/>";
			//echo json_encode($allClassifieds);
		}else{
			echo "hello l'artiste !! What's up baby ?";
		}
	}
682
683
684
   // Troisième refactor à faire sur communecter.org qui permet de netoyer les news sans target
   	
   	public function actionWashingNewsNoTarget(){
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
	  		$news=PHDB::find(News::COLLECTION);
	  		$i=0;
	  		$nbNews=count($news);
			echo "Nombre de documents appelés : ".$nbNews;
	  		foreach($news as $key => $data){
			  if($data["type"]=="news" && !@$data["target"]){
				  $i++;
				  print_r($data);
				  PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
			 // PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
			  	
				}
				else if ($data["type"]=="activityStream" && !@$data["target"]){
				$i++;
				  print_r($data);
				PHDB::update(News::COLLECTION,
							array("_id" => $data["_id"]) , 
							array('$set' => array("target.type" => Person::COLLECTION,"target.id"=>$data["author"])));
				  //PHDB::update(News::COLLECTION, array("_id"=>new MongoId($key)));
			 // PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
			  	
				}
708
			}
709
			echo "nombre de news traitées ////////////// ".$i;
710
711
712
713
		}
	}
	// Delete news with object gantts and needs
	public function actionDeleteNewsGanttsNeeds(){
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		$newsNeeds=PHDB::find(News::COLLECTION,array("type"=>"activityStream","object.objectType"=>"needs"));
		$newsGantts=PHDB::find(News::COLLECTION,array("type"=>"activityStream","object.objectType"=>"gantts"));  		$i=0;	
	  		foreach($newsNeeds as $key => $data){
			  //if(!@$data["target"]){
				  print_r($data);
				  PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
			 // PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
			 	$i++;
				//}
			}
			foreach($newsGantts as $key => $data){
				//if(!@$data["target"]){
				print_r($data);
				PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
				// PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key)));
				$i++;
				//}
			}
			echo "Nombre de news gantts ou needs suprimées : ".$i." news";
			
735
736
737
738
		}
	}
	// Quatrième refactor à faire sur communecter.org qui permet de netoyer les news dont la target n'existe pas
	public function actionWashingNewsTargetNotExist(){
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
	  		$news=PHDB::find(News::COLLECTION);
	  		foreach($news as $key => $data){
			  	if(@$data["target"]){
					if(!@$data["target"]["type"]){
						if(@$data["target"]["objectType"]){
							$parentType=$data["target"]["objectType"];
							PHDB::update(News::COLLECTION,
								array("_id" => $data["_id"]) , 
								array('$set' => array("target.type" => $parentType),
									'$unset' => array("target.objectType"=>""))			
							);
						} else{
							PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
						}
				  }
				  else if($data["target"]["type"]==Person::COLLECTION){
				  	$target = Person::getById($data["target"]["id"]);
				  	if (empty($target)){
					  	print_r($data);
				  		PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
				  	}
				  }
				  else if($data["target"]["type"]==Event::COLLECTION){
763
764
765
				  	$target = Event::getById($data["target"]["id"]);
				  	if (empty($target)){
					  	print_r($data);
766
				  		PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
767
768
				  	}
				  }
769
				  else if($data["target"]["type"]==Organization::COLLECTION){
770
771
772
				  	$target = Organization::getById($data["target"]["id"]);
				  	if (empty($target)){
					  	print_r($data);
773
				  		PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
774
				  	}
775

776
				  }
777
				  else if($data["target"]["type"]==Project::COLLECTION){
778
779
780
				  	$target = Project::getById($data["target"]["id"]);
				  	if (empty($target)){
				  		print_r($data);
781
				  		PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
782
783
				  	}
				  }	  
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
				}
			  	else {
				  	print_r($data);
				  	PHDB::update(News::COLLECTION,
								array("_id" => $data["_id"]) , 
								array('$set' => array("target.type" => Person::COLLECTION,
												"target.id" => $data["author"])
									)
					);
			  	}
			}
		}
	}
// Cinquième refactor à faire sur communecter.org qui permet de netoyer les news type activityStream dont l'object n'existe pas
	public function actionWashingNewsObjectNotExist(){
	  	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
	  		$news=PHDB::find(News::COLLECTION);
	  		$i=0;
	  		$nbNews=count($news);
			echo "Nombre de documents appelés : ".$nbNews;
	  		foreach($news as $key => $data){
		  		if($data["type"]=="activityStream"){
			  		if(@$data["object"]){
					  if($data["object"]["objectType"]==Event::COLLECTION){
					  	$target = Event::getById($data["target"]["id"]);
					  	if (empty($target)){
						  	print_r($data);
						  	$i++;
					  		//PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
					  	}
					  }
					  else if($data["object"]["objectType"]==Organization::COLLECTION){
					  	$target = Organization::getById($data["target"]["id"]);
					  	if (empty($target)){
						  	print_r($data);
						  						  	$i++;
					  		//PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
					  	}
		
					  }
					  else if($data["object"]["objectType"]==Project::COLLECTION){
					  	$target = Project::getById($data["target"]["id"]);
					  	if (empty($target)){
					  		print_r($data);
					  							  	$i++;
					  		//PHDB::remove(News::COLLECTION, array("_id"=>new MongoId($key))); 
					  	}
					  }	  
					 }
			  	}
			}
			echo "Nombre de news sans object traitées : ".$i." news";
836
837
		}
	}
838

839
	public function actionNewsPixels(){
840
841
842
843
844
845
846
847
848
849
850
851
852
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$news=PHDB::find(News::COLLECTION);
	  		$i=0;
	  		$nbNews=count($news);
			echo "Nombre de documents appelés : ".$nbNews;
			foreach($news as $key => $data){
				if($data["type"]=="pixels"){
					PHDB::update(News::COLLECTION,
						array("_id" => $data["_id"]) , 
						array('$set' => array("target.type" => "pixels","target.id"=>"", "type" => "news"),'$unset' => array("id"=>""))			
					);
					$i++;
				}
853
			}
854
			echo "Nombre de news pixels traitées : ".$i." news";
855
856
857
858
		}
	}
	// VoteDown
  	public function actionRefactorModerateVoteDown(){
859
860
861
862
863
864
865
866
867
868
869
870
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  	echo "actionRefactorModerateVoteDown => ";
			$news=PHDB::find(News::COLLECTION, array('voteDown' => array('$exists' => 1),'refactorAction' => array('$exists' => 0)));
			$i=0;
			echo count($news)." News en base avec voteDown<br/>";
			foreach($news as $key => $data){
				$map = array();
				foreach ($data['voteDown'] as $j => $reason) {
					if(!is_array($reason))$map['voteDown.'.$reason] = array('date' => new MongoDate(time())); 
				}
				if(count($map)){
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$set' => array('refactorNews' => new MongoDate(time()))));
871

872
873
874
875
876
877
878
879
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('voteDown' => 1)));
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$set' => $map, '$unset' => array('voteDownReason' => 1)));
					$i++;
				}
				elseif(isset($news['voteDownReason'])){
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('voteDownReason' => 1)));
					$i++;
				}
880
881
			}

882
883
			echo "nombre de news modifié => ".$i;
		}
884
885
886
887
	}

	// VoteUp
  	public function actionRefactorModerateVoteUp(){
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  	echo "actionRefactorModerateVoteUp => ";
			$news=PHDB::find(News::COLLECTION, array('voteUp' => array('$exists' => 1),'refactorNews' => array('$exists' => 0)));
			$i=0;
			echo count($news)." News en base avec voteUp<br/>";
			foreach($news as $key => $data){
				$map = array();
				foreach ($data['voteUp'] as $j => $reason) {
					if(!is_array($reason))$map['voteUp.'.$reason] = array('date' => new MongoDate(time())); 
				}
				if(count($map)){
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$set' => array('refactorNews' => new MongoDate(time()))));
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('voteUp' => 1)));
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$set' => $map, '$unset' => array('voteUpReason' => 1)));
					$i++;
				}
				elseif(isset($news['voteUpReason'])){
					$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('voteUpReason' => 1)));
					$i++;
				}
908
909
			}

910
911
912
			echo "nombre de news modifié => ".$i;
	  	}
	  }
913
914
915
916


	  // ReportAbuse
	public function actionRefactorModerateReportAbuse(){
917
918
919
920
921
922
923
924
925
926
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
		  	echo "actionRefactorModerateReportAbuse => ";  	
		  	$i = 0;
			$news=PHDB::find(News::COLLECTION, array('reportAbuseReason' => array('$exists' => 1)));
		  	foreach($news as $key => $data){
				$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('reportAbuseReason' => 1)));
				$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('reportAbuseCount' => 1)));
				$res = PHDB::update('news', array('_id' => $data['_id']), array('$unset' => array('reportAbuse' => 1)));
				$i++;
			}
927

928
929
			echo count($news)." News en base avec reportAbuseReason<br/>";
		}
930
931
932
933
	}



Clément Damiens's avatar
   
Clément Damiens committed
934
	/*public function actionUpdateRegion(){
935
if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981

		$newsRegions = array(
						//array("new_code","new_name","former_code","former_name"),
						array("01","Guadeloupe","01","Guadeloupe"),
						array("02","Martinique","02","Martinique"),
						array("03","Guyane","03","Guyane"),
						array("04","La Réunion","04","La Réunion"),
						array("06","Mayotte","06","Mayotte"),
						array("11","Île-de-France","11","Île-de-France"),
						array("24","Centre-Val de Loire","24","Centre"),
						array("27","Bourgogne-Franche-Comté","26","Bourgogne"),
						array("27","Bourgogne-Franche-Comté","43","Franche-Comté"),
						array("28","Normandie","23","Haute-Normandie"),
						array("28","Normandie","25","Basse-Normandie"),
						array("32","Nord-Pas-de-Calais-Picardie","31","Nord-Pas-de-Calais"),
						array("32","Nord-Pas-de-Calais-Picardie","22","Picardie"),
						array("44","Alsace-Champagne-Ardenne-Lorraine","41","Lorraine"),
						array("44","Alsace-Champagne-Ardenne-Lorraine","42","Alsace"),
						array("44","Alsace-Champagne-Ardenne-Lorraine","21","Champagne-Ardenne"),
						array("52","Pays de la Loire","52","Pays de la Loire"),
						array("53","Bretagne","53","Bretagne"),
						array("75","Aquitaine-Limousin-Poitou-Charentes","72","Aquitaine"),
						array("75","Aquitaine-Limousin-Poitou-Charentes","54","Poitou-Charentes"),
						array("75","Aquitaine-Limousin-Poitou-Charentes","74","Limousin"),
						array("76","Languedoc-Roussillon-Midi-Pyrénées","73","Midi-Pyrénées"),
						array("76","Languedoc-Roussillon-Midi-Pyrénées","91","Languedoc-Roussillon"),
						array("84","Auvergne-Rhône-Alpes","82","Rhône-Alpes"),
						array("84","Auvergne-Rhône-Alpes","83","Auvergne"),
						array("93","Provence-Alpes-Côte d'Azur","93","Provence-Alpes-Côte d'Azur"),
						array("94","Corse","94","Corse")
					);

		foreach ($newsRegions as $key => $region){

			echo "News : (".$region[0].") ".$region[1]." ---- Ancien : (".$region[2].") ".$region[3]."</br>" ;

			$cities = PHDB::find(City::COLLECTION,array("region" => $region[2]));
			$res = array("result" => false , "msg" => "La région (".$region[0].") ".$region[1]." n'existe pas");
			
			if(!empty($cities)){

				/*$res = PHDB::updateWithOption( City::COLLECTION, 
									  	array("region"=> $region[2]),
				                        array('$set' => array(	"region" => $region[0],
				                        						"regionName" => $region[1])),
				                        array("multi"=> true)
Clément Damiens's avatar
   
Clément Damiens committed
982
				                    );
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
				foreach ($cities as $key => $city) {
					$res = PHDB::update( City::COLLECTION, 
									  	array("_id"=>new MongoId($key)),
				                        array('$set' => array(	"region" => $region[0],
				                        						"regionName" => $region[1]))
				                    );

				}
				
				var_dump($res);
				echo "</br></br></br>";

			}
			else
				echo "Result : ".$res["result"]." | ".$res["msg"]."</br></br></br>";

		}

Clément Damiens's avatar
   
Clément Damiens committed
1001
	}*/
1002
1003

	public function actionUpdateUserName() {
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			//add a suffle username for pending users event if they got one
			$pendingUsers = PHDB::find(Person::COLLECTION, array("pending" => true));
			$nbPendingUser = 0;
			foreach ($pendingUsers as $key => $person) {
				$res = PHDB::update( Person::COLLECTION, 
										  	array("_id"=>new MongoId($key)),
					                        array('$set' => array(	
					                        			"username" => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, 32)), 
					                        			'$addToSet' => array("modifiedByBatch" => array("updateUserName" => new MongoDate(time()))))
1014

1015
1016
1017
1018
					                    );
				$nbPendingUser++;
			}
			echo "Number of pending user with username modified : ".$nbPendingUser;
1019
1020
1021
1022
1023
1024
		}
	}



	public function actionUpdatePreferences() {
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$nbUser = 0;
			$preferencesUsers = array(
								"publicFields" => array(),
								"privateFields" => array("email", "streetAddress", "phone", "directory", "birthDate"),
								"isOpenData" => false );
			$users = PHDB::find(Person::COLLECTION, array());
			foreach ($users as $key => $person) {
				$person["modifiedByBatch"][] = array("updatePreferences" => new MongoDate(time()));
				$res = PHDB::update(Person::COLLECTION, 
											  	array("_id"=>new MongoId($key)),
						                        array('$set' => array(	"seePreferences" => true,
						                        						"preferences" => $preferencesUsers,
						                        						"modifiedByBatch" => $person["modifiedByBatch"])
						                        					)
						                    );

				if($res["ok"] == 1){
					$nbUser++;
				}else{
					echo "<br/> Error with user id : ".$key;
				}
1047
1048
			}

1049
1050
			echo "Number of user with preferences modified : ".$nbUser;
		}
1051
1052
1053
	}

	public function actionUpdateCitiesBelgique() {
1054
1055
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			/*$cities = PHDB::find(City::COLLECTION, array("country" => "BEL"));
1056

1057
1058
1059
1060
1061
1062
1063
			foreach ($cities as $key => $city) {
				$res = PHDB::update( City::COLLECTION, 
						  	array("_id"=>new MongoId($key)),
	                        array('$set' => array(	"country" => "BE",
													"insee" => substr($city["insee"], 0, 5)."*BE",
													"dep" => substr($city["dep"], 0, 2)."*BE",
													"region" => substr($city["region"], 0, 2)."*BE"))
1064

1065
1066
	                    );
			}*/
1067

1068
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
1069

1070
1071
			foreach ($types as $keyType => $type) {
				$elts = PHDB::find($type, array("address.addressCountry" => "BEL"));
1072

1073
1074
1075
1076
1077
				foreach ($elts as $key => $elt) {
					if(!empty($elt["address"]["codeInsee"])){
						$newAddress = $elt["address"];
						$newAddress["addressCountry"] = "BE";
						$newAddress["codeInsee"] = substr($newAddress["codeInsee"], 0, 5)."*BE";
1078

1079
1080
1081
1082
1083
1084
						$res = PHDB::update($type, 
							  	array("_id"=>new MongoId($key)),
		                        array('$set' => array(	"address" => $newAddress ))
		                    );
					}
					
1085
1086
				}
			}
1087
1088
			echo "good" ;
			
1089
1090
1091
1092
1093
		}
	}


	public function actionCheckNameBelgique(){
1094
1095
1096
1097
1098
1099
1100
1101
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$cities = PHDB::find(City::COLLECTION, array("country" => "BE"));
			$nbcities = 0 ;
			foreach ($cities as $key => $city) {
				$name = $city["name"];
				$find = false ;
				if(count($city["postalCodes"]) == 1){
					
1102

1103
1104
1105
1106
1107
1108
					foreach ($city["postalCodes"] as $keyCP => $cp) {
						if(trim($cp["name"]) != trim($name)){
							$find =true;
							$cp["name"] = $name ;
							$postalCodes[$keyCP] =  $cp ;
						}
1109
1110


1111
					}
1112

1113
1114
1115
1116
1117
					if($find == true){
						$nbcities ++ ;
						$res = PHDB::update( City::COLLECTION, 
						  	array("_id"=>new MongoId($key)),
	                        array('$set' => array(	"postalCodes" => $postalCodes ))
1118

1119
1120
1121
1122
1123
	                    );
					}
				}			
			}
			echo  "NB Cities : " .$nbcities."<br>" ;
1124

1125
		}
1126
1127
1128
1129
	}


	public function actionAddGeoPosition(){
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {

				$elements = PHDB::find($type, array("geoPosition" => array('$exists' => 0), "geo" => array('$exists' => 1)));
				foreach ($elements as $key => $elt) {
					if(!empty($elt["geo"])){
						if(!empty($elt["geo"]["longitude"]) && !empty($elt["geo"]["latitude"])){
							$geoPosition = array("type"=>"Point", 
											"coordinates" => array(floatval($elt["geo"]["longitude"]), floatval($elt["geo"]["latitude"])));
							$elt["modifiedByBatch"][] = array("addGeoPosition" => new MongoDate(time()));
							$res = PHDB::update( $type, 
							  	array("_id"=>new MongoId($key)),
		                        array('$set' => array(	"geoPosition" => $geoPosition,
		                        						"modifiedByBatch" => $elt["modifiedByBatch"])), 
		                        array('upsert' => true ));
		                    $nbelement ++ ;
						}else{
							echo  $type." id : " .$key." : pas de longitude ou de latitude<br>" ;
						}	
1151
					}else{
1152
1153
1154
						echo  $type." id : " .$key." : pas de geo <br>" ;
					}

1155

1156
1157
				}

1158
1159
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
1160

1161
		}
1162
1163
1164
1165
	}


	public function actionDeleteLinksHimSelf(){
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {
				$elements = PHDB::find($type, array("links" => array('$exists' => 1)));
				foreach ($elements as $keyElt => $elt) {
					if(!empty($elt["links"])){
						$find = false;
						$newLinks = array();
						foreach(@$elt["links"] as $typeLinks => $links){
							if(array_key_exists ($keyElt , $links)){
								$find = true;
			                    unset($links[$keyElt]);
							}
							$newLinks[$typeLinks] = $links;
1181
1182
						}

1183
1184
1185
1186
1187
1188
1189
1190
1191
						if($find == true){
							$nbelement ++ ;
							$elt["modifiedByBatch"][] = array("deleteLinksHimSelf" => new MongoDate(time()));
							$res = PHDB::update( $type, 
							  	array("_id"=>new MongoId($keyElt)),
		                        array('$set' => array(	"links" => $newLinks,
		                        						"modifiedByBatch" => $elt["modifiedByBatch"])));
							echo "Suppression du link pour le type : ".$type." et l'id ".$keyElt;
						}
1192
1193
					}
				}
1194
1195
1196
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
		}
1197
1198
1199
1200
	}


	public function actionUpdateCitiesBelgiqueGeo() {
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			ini_set('memory_limit', '-1');
			$cities = PHDB::find(City::COLLECTION, array("country" => "BE"));
			$nbelement= 0 ;
			foreach ($cities as $key => $city) {
				$find = false ;
				$newCPs = array();
				foreach ($city["postalCodes"] as $keyPC => $cp) {
					if(empty($cp["geo"])){
						$find = true ;
						$cp["geo"] = $city["geo"];
						$cp["geoPosition"] = $city["geoPosition"];
					}
					$newCPs[] = $cp;
				}
				if($find == true){
					$nbelement ++ ;
					$res = PHDB::update( City::COLLECTION, 
				  		array("_id"=>new MongoId($key)),
	                	array('$set' => array("postalCodes" => $newCPs)));
1221
1222
				}
			}
1223
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
1224
1225
1226
1227
1228
		}
	}


	public function actionDeleteLinksDeprecated(){
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {
				$elements = PHDB::find($type, array("links" => array('$exists' => 1)));
				foreach (@$elements as $keyElt => $elt) {
					if(!empty($elt["links"])){
						$find = false;
						$newLinks = array();
						foreach(@$elt["links"] as $typeLinks => $links){

							foreach(@$links as $keyLink => $link){
								if(!empty($link["type"])){
									$eltL = PHDB::find($link["type"], array("_id"=>new MongoId($keyLink)));
									if(empty($eltL)){
										$find = true;
					                    unset($links[$keyLink]);
									}
									$newLinks[$typeLinks] = $links;
1248
1249
1250
								}
							}
						}
1251
1252
1253
1254
1255
1256
1257
1258
1259
						if($find == true){
							$nbelement ++ ;
							$elt["modifiedByBatch"][] = array("deleteLinksDeprecated" => new MongoDate(time()));
							$res = PHDB::update( $type, 
							  	array("_id"=>new MongoId($keyElt)),
		                        array('$set' => array(	"links" => $newLinks,
		                        						"modifiedByBatch" => $elt["modifiedByBatch"])));
							echo "Suppression de link  deprecated pour le type : ".$type." et l'id ".$keyElt."<br>" ;
						}
1260
1261
					}
				}
1262
1263
1264
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
		}
1265
	}
1266

1267
	public function actionRefactorChartProjectData(){
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$projects = PHDB::find(Project::COLLECTION, array("properties.chart" => array('$exists' => 1)));
			foreach($projects as $data){
				echo "////////// <br/>";
				echo (string)$data["_id"]."<br/>";
				$chart=array();
				$chart["open"]=array();
				foreach($data["properties"]["chart"] as $key => $value){
					$values=array("description"=>"", "value" => $value);
					$chart["open"][$key]=array();
					$chart["open"][$key]=$values;
					//echo $value."<br/>";
				}
				echo "NEW OBJECT<br/>";
				print_r($chart);
				PHDB::update(Project::COLLECTION,
					array("_id" => new MongoId((string)$data["_id"])),
					array('$set' => array("properties.chart"=> $chart))
				);

				echo "////////// <br/>";
1289
1290
1291
			}
		}
	}
1292

Clément Damiens's avatar
   
Clément Damiens committed
1293
	public function actionRemovePropertiesOfOrganizations(){
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$organizations = PHDB::find(Organization::COLLECTION, array("properties.chart" => array('$exists' => 1)));
			$nbOrgaDealWith=0;
			foreach($organizations as $data){
				PHDB::update(Organization::COLLECTION,
					array("_id" => new MongoId((string)$data["_id"])),
					array('$unset' => array("properties"=> ""))
				);
				$nbOrgaDealWith++;
			}	
			echo "nombre d'organizations traitées : ".$nbOrgaDealWith;
		}
Clément Damiens's avatar
   
Clément Damiens committed
1306
	}
1307

1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
	public function actionFixBugCoutryReunion(){
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$nbelement = 0 ;
			$elements = PHDB::find(Organization::COLLECTION, array("address.addressCountry" => "Réunion"));
			foreach (@$elements as $keyElt => $elt) {
				if(!empty($elt["address"]["postalCode"]) || !empty($elt["address"]["cp"])){
					$cpElt = (!empty($elt["address"]["postalCode"])?$elt["address"]["postalCode"]:$elt["address"]["cp"]);
					$where = array("postalCodes.postalCode" => $cpElt);
					$cities = PHDB::find("cities",$where);
					foreach (@$cities as $keyCity => $city) {
							$address = array(
						        "@type" => "PostalAddress",
						        "codeInsee" => $city["insee"],
						        "addressCountry" => $city["country"],
						        "postalCode" => $cpElt,
						        "streetAddress" => ((@$elt["address"]["streetAddress"])?trim(@$fieldValue["address"]["streetAddress"]):""),
						        "depName" => $city["depName"],
						        "regionName" => $city["regionName"],
						    	);

							$find = false;
					   		foreach ($city["postalCodes"] as $keyCp => $cp) {
					   			if($cp["postalCode"] == $cpElt){
					   				$address["addressLocality"] = $cp["name"];
					   				$geo = $cp["geo"];
					   				$geoPosition = $cp["geoPosition"];
					   				$find = true;
					   				break;
					   			}
					   		}

					   		if($find == false){
					   			$address["addressLocality"] = $city["alternateName"];
					   			$geo = $city["geo"];
					   			$geoPosition = $city["geoPosition"];
					   		}
						break;  	
					}
					
					$nbelement ++ ;
					$elt["modifiedByBatch"][] = array("fixBugCoutryReunion" => new MongoDate(time()));
					$res = PHDB::update( Organization::COLLECTION, 
					  	array("_id"=>new MongoId($keyElt)),
	                    array('$set' => array(	"address" => $address,
	                    						"geo" => $geo,
	                    						"geoPosition" => $geoPosition,
	                    						"modifiedByBatch" => $elt["modifiedByBatch"])));
					echo "Update orga : l'id ".$keyElt."<br>" ;
					
				}else{
					$nbelement ++ ;
					$elt["modifiedByBatch"][] = array("fixBugCoutryReunion" => new MongoDate(time()));
					$res = PHDB::update( Organization::COLLECTION, 
					  	array("_id"=>new MongoId($keyElt)),
	                    array('$unset' => array("address" => ""),
	                    		'$set' => array( "modifiedByBatch" => $elt["modifiedByBatch"])));
					echo "Update orga : l'id ".$keyElt."<br>" ;
1365
1366
1367
				}
				
			
1368
1369
1370
			}
					
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
1371
1372
1373
1374
1375
		}
	}


	public function actionRefactorSource(){
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {
				$elements = PHDB::find($type, array("source" => array('$exists' => 1)));
				if(!empty($elements)){
					foreach (@$elements as $keyElt => $elt) {

						if(!empty($elt["source"])){
							$newsource = array();
							if(!empty($elt["source"]["key"]) && empty($elt["source"]["keys"])){
								$newsource["insertOrign"] = "import" ;
								$newsource["key"] = $elt["source"]["key"];
								$newsource["keys"][] = $elt["source"]["key"];

								if(!empty($elt["source"]["url"]))
									$newsource["url"] = $elt["source"]["url"];
								if(!empty($elt["source"]["id"])){
									if(!empty($elt["source"]["id"]['$numberLong']))

										$newsource["id"] = $elt["source"]["id"]['$numberLong'];

									else
										$newsource["id"] = $elt["source"]["id"];
								}
								if(!empty($elt["source"]["update"]))
									$newsource["update"] = $elt["source"]["update"];
								
								$nbelement ++ ;
								$elt["modifiedByBatch"][] = array("RefactorSource" => new MongoDate(time()));

								try {
									$res = PHDB::update( $type, 
								  		array("_id"=>new MongoId($keyElt)),
			                        	array('$set' => array(	"source" => $newsource,
			                        							"modifiedByBatch" => $elt["modifiedByBatch"])));
								} catch (MongoWriteConcernException $e) {
									echo("Erreur à la mise à jour de l'élément ".$type." avec l'id ".$keyElt);
									die();
								}
								echo "Elt mis a jour : ".$type." et l'id ".$keyElt."<br>" ;
1417
1418
1419
1420
1421
1422


							}
						}
					}
				}
1423
1424
1425
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
		}
1426
1427
1428
1429
1430
1431
1432
	}

	/**
	 * Refactor events with no timezone depending on country
	 * Must be launch only once !
	 */
	public function actionAddTZOnEventDates(){
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$nbelement = 0 ;
			$nbelementPassed = 0 ;
			$nbelementRE = 0 ;
			$nbelementBE = 0 ;
			$nbelementFR = 0 ;
			$nbelementNC = 0 ;
			$nbelementUnknown = 0 ;
			$nbelementDateString = 0 ;
			$timezoneArray = array("RE" => 4, "FR" => 1, "NC" => 11, "BE" => 1);

			$elements = PHDB::find(Event::COLLECTION, array());
			foreach (@$elements as $keyElt => $elt) {
				if (isset($elt["modifiedByBatch"])) {
					$alreadyUpdated = false;
					foreach ($elt["modifiedByBatch"] as $value) {
						if (isset($value["addTZOnEventDates"])) {
							$nbelementPassed++;
							$alreadyUpdated = true;
							break;
						}
1454
					}
1455
					if ($alreadyUpdated) continue;
1456
				}
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
				if(empty($elt["address"]["addressCountry"]) || 
				   empty($timezoneArray[$elt["address"]["addressCountry"]])) {
					echo "Pas de country ou country inconnu pour l'événement : ".$keyElt."</br>";
					$nbelementUnknown++;
					continue;
				}
				$timezone = $timezoneArray[$elt["address"]["addressCountry"]];
				if (isset($elt["startDate"]) && isset($elt["endDate"]) && (gettype($elt["startDate"]) == "object" && gettype($elt["endDate"]) == "object")) {
					//Set TZ to UTC in order to be the same than Mongo
					$startDate = new DateTime(date(DateTime::ISO8601, $elt["startDate"]->sec));
					$startDate = $startDate->sub(new DateInterval("PT".$timezone."H"));
					$endDate = new DateTime(date(DateTime::ISO8601, $elt["endDate"]->sec));
					$endDate = $endDate->sub(new DateInterval("PT".$timezone."H"));
					//$startDate = $elt["startDate"]->toDateTime()->sub(new DateInterval("PT".$timezone."H"));
					//$endDate = $elt["endDate"]->toDateTime()->sub(new DateInterval("PT".$timezone."H"));
					${'nbelement'.$elt["address"]["addressCountry"]}++;
				//On en profite pour revoir les dates des événements qui sont en string ou sans date
				} else {
					$nbelementDateString++;
					$startDate = new DateTime();
					$startDate->sub(new DateInterval("P1D"));
					$endDate = new DateTime();
					$endDate->sub(new DateInterval("P2D"));
				}
				//update the event
				$elt["modifiedByBatch"][] = array("addTZOnEventDates" => new MongoDate(time()));
				PHDB::update( Event::COLLECTION, array("_id" => new MongoId($keyElt)), 
			                          array('$set' => array(
			                          		"startDate" => new MongoDate($startDate->getTimestamp()), 
			                          		"endDate" => new MongoDate($endDate->getTimestamp()),
			                        		"modifiedByBatch" => $elt["modifiedByBatch"])));
				$nbelement++;
1489
			}
1490
1491
1492
1493
1494
1495
1496
1497
1498
					
			echo  "Event Reunion mis à jours: " .$nbelementRE."<br>" ;
			echo  "Event France mis à jours: " .$nbelementFR."<br>" ;
			echo  "Event Belgique mis à jours: " .$nbelementBE."<br>" ;
			echo  "Event NC mis à jours: " .$nbelementNC."<br>" ;
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
			echo  "NB Element passé : " .$nbelementPassed."<br>" ;
			echo  "NB Element inconnu : " .$nbelementUnknown."<br>" ;
			echo  "NB Element date en string : " .$nbelementDateString."<br>" ;
1499
1500
1501
1502
1503
		}
	}


	/*public function actionNameHtmlSpecialCaractere(){
1504
	if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
		$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
		$nbelement = 0 ;
		foreach ($types as $keyType => $type) {
			$elements = PHDB::find($type, array("name" => array('$exists' => 1)));
			if(!empty($elements)){
				foreach (@$elements as $keyElt => $elt) {
					if(!empty($elt["name"])){
						$nbelement ++ ;
						$elt["modifiedByBatch"][] = array("NameHtmlSpecialCaractere" => new MongoDate(time()));
						try {
							$res = PHDB::update( $type, 
						  		array("_id"=>new MongoId($keyElt)),
	                        	array('$set' => array(	"name" => htmlspecialchars($elt["name"]),
	                        							"modifiedByBatch" => $elt["modifiedByBatch"])));
						} catch (MongoWriteConcernException $e) {
							echo("Erreur à la mise à jour de l'élément ".$type." avec l'id ".$keyElt);
							die();
						}
						echo "Elt mis a jour : ".$type." et l'id ".$keyElt."<br>" ;
					}
				}
			}
		}		
		echo  "NB Element mis à jours: " .$nbelement."<br>" ;
1529
	}}*/
1530
1531
1532


	public function actionNameHtmlSpecialCharsDecode(){
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {
				$elements = PHDB::find($type, array("name" => array('$exists' => 1)));
				if(!empty($elements)){
					foreach (@$elements as $keyElt => $elt) {
						if(!empty($elt["name"])){
							$nbelement ++ ;
							$elt["modifiedByBatch"][] = array("NameHtmlSpecialCharsDecode" => new MongoDate(time()));
1543
1544
1545
							try {
								$res = PHDB::update( $type, 
							  		array("_id"=>new MongoId($keyElt)),
1546
		                        	array('$set' => array(	"name" => htmlspecialchars_decode($elt["name"]),
1547
1548
1549
1550
1551
1552
1553
1554
1555
		                        							"modifiedByBatch" => $elt["modifiedByBatch"])));
							} catch (MongoWriteConcernException $e) {
								echo("Erreur à la mise à jour de l'élément ".$type." avec l'id ".$keyElt);
								die();
							}
							echo "Elt mis a jour : ".$type." et l'id ".$keyElt."<br>" ;
						}
					}
				}
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
		}
	}

	public function actionAddDepAndRegionAndCountryInAddress(){
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){


			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			$arrayDep = array("address.depName" => array('$exists' => 0));
			$arrayRegion = array("address.regionName" => array('$exists' => 0));
			$arrayCountry = array("address.addressCountry" => array('$exists' => 0));
			$arrayStreet = array("address.streetAddress" => array('$exists' => 0));
			$where = array('$and' => array(
							array("address" => array('$exists' => 1)), 
							array('$or' => array($arrayDep, $arrayRegion, $arrayCountry, $arrayStreet))
						));
			
			foreach ($types as $keyType => $type) {
				
				$elements = PHDB::find($type, $where);
				
				if(!empty($elements)){
					foreach (@$elements as $keyElt => $elt) {
						if(!empty($elt["name"])){
							$nbelement ++ ;
							$elt["modifiedByBatch"][] = array("AddDepAndRegionAndCountryInAddress" => new MongoDate(time()));
							$address = $elt["address"];

							if (isset($address["codeInsee"])) {
								$depAndRegion = City::getDepAndRegionByInsee($address["codeInsee"]);

								$address["depName"] = (empty($depAndRegion["depName"]) ? "" : $depAndRegion["depName"]);
								$address["regionName"] = (empty($depAndRegion["regionName"]) ? "" : $depAndRegion["regionName"]);
								$address["addressCountry"] = (empty($depAndRegion["country"]) ? "" : $depAndRegion["country"]);
								$address["streetAddress"] = (empty($elt["address"]["streetAddress"]) ? "" : $elt["address"]["streetAddress"]);
								try {
									$res = PHDB::update( $type, 
								  		array("_id"=>new MongoId($keyElt)),
			                        	array('$set' => array(	"address" => $address,
			                        							"modifiedByBatch" => $elt["modifiedByBatch"])));
								} catch (MongoWriteConcernException $e) {
									echo("Erreur à la mise à jour de l'élément ".$type." avec l'id ".$keyElt);
									die();
								}
								echo "Elt mis a jour : ".$type." et l'id ".$keyElt."<br>" ;
							} else {
								echo "Pas de mise a jour : ".$type." et l'id ".$keyElt."<br>" ;
							}
						}
					}
				}
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
		}
1613
1614
1615
	}

	public function actionHtmlToMarkdown(){
1616
1617
1618
1619
1620
1621
1622
1623
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$html = "<h3> TEst </h3>
					<p>Welcome to the demo:</p>
					<ol>
					<li>Write Markdown text on the left</li>
					<li>Hit the <strong>Parse</strong> button or <code>⌘ + Enter</code></li>
					<li>See the result to on the right</li>
					</ol>" ;
1624

1625
			echo $html ;
1626

1627
			echo "<br/><br/><br/><br/>";
1628

1629
1630
			
			
1631

1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
			try {
	            //$mailError = new MailError($_POST);
	            $converter = new Htmlconverter();
				$mark = $converter->convert($html);
	        } catch (CTKException $e) {
	            Rest::sendResponse(450, "Webhook : ".$e->getMessage());
	            die;
	        }
			echo $mark;
		}
1642
1643
1644
	}

	public function actionDescInHtml(){
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION, Project::COLLECTION, Event::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {
				$elements = PHDB::find($type, array("description" => array('$exists' => 1)));
				if(!empty($elements)){
					foreach (@$elements as $keyElt => $elt) {
						if(!empty($elt["name"])){
							$nbelement ++ ;
							$elt["modifiedByBatch"][] = array("DescInHtml" => new MongoDate(time()));
							try {
								$res = PHDB::update( $type, 
							  		array("_id"=>new MongoId($keyElt)),
		                        	array('$set' => array(	"descriptionHTML" => true,
		                        							"modifiedByBatch" => $elt["modifiedByBatch"])));
							} catch (MongoWriteConcernException $e) {
								echo("Erreur à la mise à jour de l'élément ".$type." avec l'id ".$keyElt);
								die();
							}
							echo "Elt mis a jour : ".$type." et l'id ".$keyElt."<br>" ;
1665
1666
1667
						}
					}
				}
1668
1669
1670
			}		
			echo  "NB Element mis à jours: " .$nbelement."<br>" ;
		}
1671
1672
	}

Raphael's avatar
Raphael committed
1673
	public function actionChangePhoneObjectToArray(){
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
		if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
			$types = array(Person::COLLECTION, Organization::COLLECTION);
			$nbelement = 0 ;
			foreach ($types as $keyType => $type) {
				$elements = PHDB::find($type, array("telephone" => array('$exists' => 1)));
				if(!empty($elements)){
					foreach (@$elements as $keyElt => $elt) {
						if(!empty($elt["name"])){
							$nbelement ++ ;
							$elt["modifiedByBatch"][] = array("ChangePhoneObjectToArray" => new MongoDate(time()));
							
							if(!empty($elt["telephone"]["fixe"])) {
								$elt["telephone"]["fixe"] = json_decode(json_encode($elt["telephone"]["fixe"]), true);
							}
Raphael's avatar
Raphael committed
1688

1689
1690
1691
							if(!empty($elt["telephone"]["mobile"])){
								$elt["telephone"]["fixe"] = json_decode(json_encode($elt["telephone"]["mobile"]), true);
							}
Raphael's avatar
Raphael committed
1692

1693
1694
1695
							if(!empty($elt["telephone"]["fax"]) ){
								$elt["telephone"]["fax"] = json_decode(json_encode($elt["telephone"]["fax"]), true);
							}
Raphael's avatar
Raphael committed
1696

1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
							try {
								$res = PHDB::update( $type, 
							  		array("_id"=>new MongoId($keyElt)),